Click here to Skip to main content
15,899,124 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i get this error anytime i try to upload a file in my asp.net mvc application. Can anyone help me out. The error thrown is a System.UnauthorisedAccesException

Access to the path 'C:\inetpub\wwwroot\IBGTxalert\TxAlert\TxAlert.Web\Files\linqtoexcel.xlsx' is denied.
Posted
Comments
DaveAuld 28-Aug-11 11:41am    
Sounds like a basic security issue. Is the account used for the WWW User listed in the security pane for the folder in question with suitable permissions?
Keith Barrow 28-Aug-11 17:01pm    
It is a bad plan to put the upload folder in the application path, it opens up security vulnerabilities. Other than that see Dave Auld's answer: it looks like the account the website is running under doesn't have write permission to that folder.

1 solution

You are trying to write/upload a file in the non granted wwwroot folder. Itz best practice to capture these kinds of securite exception at
C#
try
{
    ... Upload code ...
}
catch (System.UnauthorizedAccessException ex)
{
    ... handles exception ..
}


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.

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.
 
Share this answer
 

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