Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have an MVC application that uses Directory.getfiles() to scrape a network share for a file list and displays them to the used. This has worked fine on my development machine, but when I have deployed this to the web server I get the following:

XML
Access to the path {path}; 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 [path]; 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.


I assume it's because my desktop workstation has my permissions, and the web server does not. How the servers are setup is we have a 2012 R2 Machine running iis8 and a file server hosting the file shares.

How can I give asp permission to the file shares? or alternatively how can I impersonate the current user so they can get at the files if they have access or how can I impersonate a service account with the correct permissions?

thanks!
Posted
Comments
F-ES Sitecore 4-Aug-15 11:31am    
Change the anonymous user to an account that has the access you need.

1 solution

It's not that the workstation has your permissions. YOU have the permissions. Well, your account does. Anything you launch is launched AS YOU and inherits your secruity token.

This includes the IIS Express web server that is launched when you debug your site on your dev machine. Since it's running as you it has access to everything you do, including that share.

When you deploy your app to a real web server, IIS 8, it's running your code under a service account that is pretty restricted. It doesn't have access to network resources for security reasons. Because of this it has no access to the share you're trying to get at.

To fix this, you have to create an account that is specifically setup to execute your website. It should also have whatever access it needs to access the share. Once the account is setup, you go into the IIS Manager and create an Application Pool to run your website and tell it the username and password for the account you created.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 4-Aug-15 12:34pm    
5ed.
—SA
Josiah Bradbury 5-Aug-15 8:09am    
Alright, what I did last night was go in an create a new application pool, I added myself as the identity domain\user and my password. Late last night I changed the application pool of the site for about 30 minutes. The site worked, but the same issue.
Dave Kreskowiak 5-Aug-15 8:10am    
Are you using UNC paths in your code or mapped drive letters? Drive mappings won't exist for the service account. You should ALWAYS be using UNC paths.
Josiah Bradbury 5-Aug-15 8:16am    
I am using \\Server\Share\Folder\Folder
Dave Kreskowiak 5-Aug-15 11:49am    
Is the account a domain account that the share expects or is it local to the machine running IIS?

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