0
votes

I published my website on the IIS6.

When saving a file by File.WriteAllText("C:\" + txtSaveExport.Text + ".CSV", b.ToString());. Its gives an error as:

em.UnauthorizedAccessException: Access to the path 'C:\hj.CSV' 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 and IIS 7, and the configured application pool identity on IIS 7.5) 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.``

How can this be handled?

2
what you are doing is totally not recommended, but if you just want to do it , give write access Network Service on your C drive.Furqan Hameedi
That I dont want to do Sir. Since wherever this website will run then it infers on that comp. its required to give the permission.Aada
well in that case, you should not write in "C:\" drive, rather you should use a specific folder like "~\APP_DATA" application folder , to be used for such actions in asp.net. you have to give the write permissions though on the app_data folder.Furqan Hameedi
Sorry to mention sir, I need to save in the local machine and not on the server.Aada
server side code cannot access client's machine in anyway. I recommend you research a bit on what web application are? before you write your next server side code.Furqan Hameedi

2 Answers

1
votes

You need to give writing permissions to the Aspnet user in that folder.

See this: http://devnet.logixml.com/rdPage.aspx?rdReport=Article&dnDocID=209

Best regards.

0
votes

It's not a good idea to write to a variable directory under C: drive. I suggest you not to give permissions to write under C, rather, write to a directory under your web app's directory, which you can get by Server.MapPath("~"). Make sure you give write access to the application pool's user account to whatever folder under your app directory, and you'll be much safer.