"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
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.
If there is no "Sharing" tab:
– Open Registry Editor (Start > Run > regedit)
– Take a backup of Registry (File > Export) to an external storage
– FindHKEY_CLASSES_ROOT\Directory\shellex\PropertySheetHandlers\Sharing
If the folder does not exist, create it.
– There should be a (Default) value with typeREG_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 theforceguest
entry value to0
- 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".
Are you using
ApplicationPoolIdentity
to run your application pools? In this case, you should give permission toCOMPUTER$
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
- How to access network files from IIS applications
- Share and NTFS permissions
- Sharing tab missing
Source: https://port135.com/solved-access-path-denied/
Posted by: sabinasamicke0194875.blogspot.com
Post a Comment