R – Access to a path denied trying to write and read a file in asp.net web application

filepermissions

I have file writing permission denied problem in my web application,

below is the error i'm getting

Access to the path 'c:\inetpub\wwwroot\autohyperlink\files\test.txt' 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\autohyperlink\files\test.txt' 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 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.

the error is here

Line 130: FileStream file1 = new FileStream(Server.MapPath("~\files\test.txt"), FileMode.Create, FileAccess.Write);

how can i solve this problem

please help me

Thanks

Best Answer

I dont mean to be derisive but have you tried doing what it says and granting the worker process read/write access to that folder/file?