Access is denied
-
Hi, guys and girls I want to access a file in my ASP.net routine but it is denied. Following is the prompt information, but I don't understand it. What shold I do? Configure IIS manuslly or other things? Thanks a lot. Access to the path "c:\inetpub\wwwroot\Weblog\Entires\Entry.xml" is denied. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.UnauthorizedAccessException: Access to the path "c:\inetpub\wwwroot\Weblog\Entires\Entry.xml" is denied. "ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user. To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access. Source Error: Line 71: string filepath = EntryFilePath+@"\"+ filename; Line 72: Line 73: FileStream file = new FileStream(filepath,FileMode.Open); Line 74: Line 75: //Create a serializer Source File: c:\inetpub\wwwroot\weblog\global.asax.cs Line: 73 -------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573 vigorous
-
Hi, guys and girls I want to access a file in my ASP.net routine but it is denied. Following is the prompt information, but I don't understand it. What shold I do? Configure IIS manuslly or other things? Thanks a lot. Access to the path "c:\inetpub\wwwroot\Weblog\Entires\Entry.xml" is denied. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.UnauthorizedAccessException: Access to the path "c:\inetpub\wwwroot\Weblog\Entires\Entry.xml" is denied. "ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user. To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access. Source Error: Line 71: string filepath = EntryFilePath+@"\"+ filename; Line 72: Line 73: FileStream file = new FileStream(filepath,FileMode.Open); Line 74: Line 75: //Create a serializer Source File: c:\inetpub\wwwroot\weblog\global.asax.cs Line: 73 -------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573 vigorous
Because you don't specify the FileAccess in the constructor, then it is given the read/write access to the file while the ASPNET account basically does not have write access, and the FileMode parameter is just used to control how a file is opened. So there are two options for you here, it depends on your requirement. If you only need to read the file contents, you then should specify the FileAccess value in the constructor like this:
FileStream file = new FileStream(filepath,FileMode.Open, FileAccess.Read);
If you are planning to read/write that file, you need to grant ASP.NET write access to the file.
-
Because you don't specify the FileAccess in the constructor, then it is given the read/write access to the file while the ASPNET account basically does not have write access, and the FileMode parameter is just used to control how a file is opened. So there are two options for you here, it depends on your requirement. If you only need to read the file contents, you then should specify the FileAccess value in the constructor like this:
FileStream file = new FileStream(filepath,FileMode.Open, FileAccess.Read);
If you are planning to read/write that file, you need to grant ASP.NET write access to the file.
Thank you for the advice. You are right. Now I can access the file in read mode. If I want to write it, how can I grant ASP.net the authorization? Thanks a lot vigorous
-
Thank you for the advice. You are right. Now I can access the file in read mode. If I want to write it, how can I grant ASP.net the authorization? Thanks a lot vigorous
You can right click on a file or folder that you want to grant ASP.NET write access, and hit Properties to open the Properties dialog box. On the Security tab, you click Add to add the ASPNET account to the list, and assign Write permission to it. There is one thing that you should be awared that you will not the Security tab in the Properties dialog if you are not joined to a domain. To display the Security tab, you should first open Folder Options ( go to Control Panel and see Folder Options or open Window Explorer, hit Tools menu and see Folder Options). On the View tad, under Advanced settings, clear "Use simple file sharing (Recommended)". In addition, you can also use impersonation to make your application able to write a file or change the account that the ASP.NET worker runs under to one with more permissions.
-
You can right click on a file or folder that you want to grant ASP.NET write access, and hit Properties to open the Properties dialog box. On the Security tab, you click Add to add the ASPNET account to the list, and assign Write permission to it. There is one thing that you should be awared that you will not the Security tab in the Properties dialog if you are not joined to a domain. To display the Security tab, you should first open Folder Options ( go to Control Panel and see Folder Options or open Window Explorer, hit Tools menu and see Folder Options). On the View tad, under Advanced settings, clear "Use simple file sharing (Recommended)". In addition, you can also use impersonation to make your application able to write a file or change the account that the ASP.NET worker runs under to one with more permissions.
Hi, I did it as you instructed but the file also can't be accessed with write mode. One question for ASP.NET account. what 's the meaning? Is it my user account? By the way I found the folder 's properties is always read-only even I chang it. The read-only properties comes back again. Do you think it is the reason? Anyway how can I write the file in ASP.NET? Thanks a lot. vigorous
-
Hi, I did it as you instructed but the file also can't be accessed with write mode. One question for ASP.NET account. what 's the meaning? Is it my user account? By the way I found the folder 's properties is always read-only even I chang it. The read-only properties comes back again. Do you think it is the reason? Anyway how can I write the file in ASP.NET? Thanks a lot. vigorous
The ASPNET account is normally used to run the ASP.NET worker process(aspnet_wp.exe), and it is automatically created during installation of the .Net framework. This account basically has limited permissions on the server mainly for the security reason. For more information on this account, you can look at this document: http://www.gotdotnet.com/team/upgrade/v1/aspnet_account_readme.doc[^] You can consult this document to see how to configure the process identity: http://support.microsoft.com/default.aspx?scid=kb;en-us;317012[^] The sample code demonstrates how write a file in ASP.NET, this method writes some text to the text.txt file located in the Data folder. To use this method, you just need to grant ASP.NET write access to the Data folder:
private void WriteToTextFile(string text) { string path = Server.MapPath("Data/text.txt"); FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write); StreamWriter writer = new StreamWriter(stream); writer.Write(text); writer.Close(); stream.Close(); }
If you write to a file which is in read-only mode, the application will throw an error. I think you don't need to worry about what you found on the folder's properties.
-
The ASPNET account is normally used to run the ASP.NET worker process(aspnet_wp.exe), and it is automatically created during installation of the .Net framework. This account basically has limited permissions on the server mainly for the security reason. For more information on this account, you can look at this document: http://www.gotdotnet.com/team/upgrade/v1/aspnet_account_readme.doc[^] You can consult this document to see how to configure the process identity: http://support.microsoft.com/default.aspx?scid=kb;en-us;317012[^] The sample code demonstrates how write a file in ASP.NET, this method writes some text to the text.txt file located in the Data folder. To use this method, you just need to grant ASP.NET write access to the Data folder:
private void WriteToTextFile(string text) { string path = Server.MapPath("Data/text.txt"); FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write); StreamWriter writer = new StreamWriter(stream); writer.Write(text); writer.Close(); stream.Close(); }
If you write to a file which is in read-only mode, the application will throw an error. I think you don't need to worry about what you found on the folder's properties.
Really thank you very much for your great help. Now I can write the file. You are really a kind person and love to help others. Thanks again. vigorous
-
Really thank you very much for your great help. Now I can write the file. You are really a kind person and love to help others. Thanks again. vigorous