Home » Development » Access to the path is denied (Solved)

Access to the path is denied (Solved)

“Access to the path is denied” error is one of the most common issues ASP.NET developers come across while working with network resources in their applications. There is no straightforward solution to this problem. However, there are several things you should check to solve it.

Server Error in ‘/’ Application.
Access to the path X 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 is denied" error message
“Access to the path is denied” error message

Looking for best practices for session state and cookies in ASP.NET applications? Check this post out.

Solution for “Access to the path is denied” error

The root cause is that the application pool which is hosting your web application is not able to access to the shared folder you specified in your code. Therefore, it throws “Access to the path is denied” message.

Go through the recommendations below to find out why the application pool can’t access to the network resource.

  • Did you give “Security” and “Sharing” permissions to the application pool identity? Make sure the account has required permissions in both tabs.
Permissions to solve "Access to the path is denied" error
First step is to check permissions in “Security” and “Sharing” tabs

If there is no “Sharing” tab: 

– Open Registry Editor (Start > Run > regedit)
– Take a backup of Registry (File > Export) to an external storage
– Find HKEY_CLASSES_ROOT\Directory\shellex\PropertySheetHandlers\Sharing
If the folder does not exist, create it.
– There should be a (Default) value with type REG_SZ and Data {f81e9010-6ea4-11ce-a7ff-00aa003ca9f6}
The Data is blank? Double click on it and paste in {f81e9010-6ea4-11ce-a7ff-00aa003ca9f6}

The “Sharing” tab is still not displayed? Go to “Folder Options“. Check “Use Sharing Wizard (Recommended)

Still not displayed? In regedit, find HKLM\System\CCS\Control\Lsa\forceguest. Modify the forceguest entry value to 0

  • Is impersonation enabled? In order to check it: “IIS Manager > Server name > Sites > Site name > Authentication > ASP.NET Impersonation”. If impersonation is enabled, impersonated user(s) will need permission on the shared folder. 
  • Do you have a virtual directory? If any virtual directories are used, please make sure they use application pool identity account in their pass-through authentication settings.  

More to consider

  • After making changes to application pool identity, please make sure to recycle , stop, and then start the application pool.
  • Are you able to open the shared folder in your web server by using the credentials of application pool identity account? Check it: “Start > Run > \\server-name\shared-folder”.  
  • In the server that hosts the shared folder, check for failed logon attempts to see which user was used to access to shared folder. In order to check it: “Start > Event Viewer > Windows Logs > Security > Audit Failure“.
Event viewer to identify the cause of "Access to the path is denied" error
Find out which account is used to access to the network resource

Are you using ApplicationPoolIdentity to run your application pools? In this case, you should give permission to COMPUTER$ account on the network resource.

In conclusion, your effort to solve this problem should focus on the application pool identity account and shared folder permission. If you are still not able to solve the problem, please leave a comment here.

References

Ned Sahin

Blogger for 20 years. Former Microsoft Engineer. Author of six books. I love creating helpful content and sharing with the world. Reach me out for any questions or feedback.

2 thoughts on “Access to the path is denied (Solved)”

  1. Hi;
    I tried to upload a CV word file to website for job application, I got this message:
    Access to the path ‘D:\Websites\GIU\docs\content\career\cv\c12b3f1337174430839675ebccc15b95.docx’ is denied
    I don’t know how to resolve it
    the site for the job vacancies
    I’ll apricate helping me to solve this issue.
    Regrds.

    Reply

Leave a Comment