File.Copy problem in Windows 2003
-
..... String fromStr = @"Mymapp\origin.txt"; String txtFile = @"C:\Inetpub\wwwroot\newFile.txt"; File.Delete(txtFile); File.Copy(fromStr, txtFile); ...... This works fine on Windows XP. It WORKED fine on Windows 2003 some days ago, but suddenly it stopped working on Windows 2003. I get something like (in swedish) "Access to the path C:\Inetpub\wwwroot\newFile.txt denied" I have given all rights to 'NETWORK SERVICE' but it doesn't help. It removes 'txtFile' which it should do, but it doesn't create a new one. Any ideas?
-
..... String fromStr = @"Mymapp\origin.txt"; String txtFile = @"C:\Inetpub\wwwroot\newFile.txt"; File.Delete(txtFile); File.Copy(fromStr, txtFile); ...... This works fine on Windows XP. It WORKED fine on Windows 2003 some days ago, but suddenly it stopped working on Windows 2003. I get something like (in swedish) "Access to the path C:\Inetpub\wwwroot\newFile.txt denied" I have given all rights to 'NETWORK SERVICE' but it doesn't help. It removes 'txtFile' which it should do, but it doesn't create a new one. Any ideas?
Did the privileges on the folder (c:\inetpub\wwwroot) change?
-
Did the privileges on the folder (c:\inetpub\wwwroot) change?
I simplified the code before. It should more be like this: String strFile = @"C:\Documents and Settings\Administrator\Application Data\aFolder\anotherFolder\readFrom file.xxx"; String txtFile = @"C:\Inetpub\wwwroot\theWebFolder\textfiles\textFile.txt"; File.Delete(txtFile); File.Copy(strFile, txtFile); The folder 'textfiles' still has all rights it needs. I deleted it, created a new one, gave it all rights but it didn't help. So I tried to add in the web.config file and then it worked!!! BUT I have to log in via a Windows log in form. So I changed to but then I got "Server Error in '/traderamail' Application........ This tag should then have its "mode" attribute set to "Off"."... though I have set . Still I wonder why it work on XP and not on Windows 2003.
-
I simplified the code before. It should more be like this: String strFile = @"C:\Documents and Settings\Administrator\Application Data\aFolder\anotherFolder\readFrom file.xxx"; String txtFile = @"C:\Inetpub\wwwroot\theWebFolder\textfiles\textFile.txt"; File.Delete(txtFile); File.Copy(strFile, txtFile); The folder 'textfiles' still has all rights it needs. I deleted it, created a new one, gave it all rights but it didn't help. So I tried to add in the web.config file and then it worked!!! BUT I have to log in via a Windows log in form. So I changed to but then I got "Server Error in '/traderamail' Application........ This tag should then have its "mode" attribute set to "Off"."... though I have set . Still I wonder why it work on XP and not on Windows 2003.
Okay, I would think that if it worked when you turned on identity impersonation, then you are definitely dealing with a permissions issue. The Windows login that you used had all necessary privileges to the files and folder to perform the delete and copy. If impersonation is turned off, then the ASPNET user account would have to have the proper permissions to the files and folder.
-
Okay, I would think that if it worked when you turned on identity impersonation, then you are definitely dealing with a permissions issue. The Windows login that you used had all necessary privileges to the files and folder to perform the delete and copy. If impersonation is turned off, then the ASPNET user account would have to have the proper permissions to the files and folder.
Ok. But what more can I do than to give NETWORK SERVICE all rights it should need? I tried to give it to ASPNET but that works for Windows XP, not Windows 2003. I checked the file in the map that was given the rigths and it's all there. Is there somewhere else I can give these rights? Or must I reinstall Windows 2003?
-
Ok. But what more can I do than to give NETWORK SERVICE all rights it should need? I tried to give it to ASPNET but that works for Windows XP, not Windows 2003. I checked the file in the map that was given the rigths and it's all there. Is there somewhere else I can give these rights? Or must I reinstall Windows 2003?
Are you absolutely certain that the aspnet_wp.exe process is running under the NETWORK SERVICE account? and if so, are you absolutely certain that the NETWORK SERVICE account has read/write privileges to both the file and the containing folder? You might double-check your machine.config file's processModel[^] configuration section (particularly username & password, and the impersonation settings) to be certain of the security account context under which aspnet_wp.exe is executing. If all that checks out, and you are absolutely certain the account priviliges are correct, then maybe the issue deals with ASP.NET code access security[^] settings for your application & server. FileIO is restricted in the Medium and Low security zones - perhaps that's what is going on? You may also find the Windows Server 2003 ASP.NET Security[^] documentation useful.
-
Are you absolutely certain that the aspnet_wp.exe process is running under the NETWORK SERVICE account? and if so, are you absolutely certain that the NETWORK SERVICE account has read/write privileges to both the file and the containing folder? You might double-check your machine.config file's processModel[^] configuration section (particularly username & password, and the impersonation settings) to be certain of the security account context under which aspnet_wp.exe is executing. If all that checks out, and you are absolutely certain the account priviliges are correct, then maybe the issue deals with ASP.NET code access security[^] settings for your application & server. FileIO is restricted in the Medium and Low security zones - perhaps that's what is going on? You may also find the Windows Server 2003 ASP.NET Security[^] documentation useful.
Where do I find if aspnet_wp.exe process is running under the NETWORK SERVICE account? I checked the properties->security of C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_wp.exe and there no 'NETWORK SERVICE' there, just 'SERVICE' with read/run and read privileges. The folder to the denied file has all privileges and files in the folder inherit those privileges. I tried IIS->Application pool->properties->Identity and it says: Predefined: Network service. I don't know what more to do there.