Click here to Skip to main content
15,847,750 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

i have web app built in c#.

where i'm using file to upload.

c# code
string FilePath = Server.MapPath(FolderPath + FileName);

the above code is working fine on local machine but after publishing the web app on domain, i'm getting this error on uploading of file.

Access to the path 'h:\root\home\fgsons-001\www\root\gis\Files\GIS-25-01-2015.xlsx' 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 'h:\root\home\fgsons-001\www\root\gis\Files\GIS-25-01-2015.xlsx' 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 <identity impersonate="true"/>, 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 File 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.

plz help me.

CHill60 26-Jan-15 10:34am    
Did you try following the instructions in the exception message?

1 solution

An application running in IIS
runs with a so-called Application-Pool Identity.
This is the default.

Please read:[^]
If your application pool is "DefaultAppPool"
you must assign rights to user "IIS AppPool\DefaultAppPool"

You can also assign a different identity e.g. LocalSystem
Share this answer
abdul subhan mohammed 26-Jan-15 10:56am    
locally its running awesome, but on access from the website its getting the error.
TheRealSteveJudge 26-Jan-15 11:00am    
OK. This is also what I understood.
But if you have hosted your application on the Internet Information Server
then you must grant rights to the used application pool.
Dave Kreskowiak 26-Jan-15 11:20am    
Dude, understand something. The IIS server hosting your app doesn't give a sh*t how well it works on your dev machine.

The reason it work on your dev machine and not on the IIS server is because when you debug the site on your dev machine, the ASP.NET server is running as YOU, not the account the IIS server is using. This means that the dev server you're running your code under has all the permissions that YOU do and so it can go to wherever in the filesystem you can and do whatever you can.

In the production IIS server, this is not the case.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900