IIS: System.UnauthorizedAccessException: Access to the path - asp.net

I have a website and it sits on the IIS Server and I have a folder on another server the file server. I have set the Virtual directory to the folder on the fileserver. This application both servers are on the same domain, but in the future I will have serves that are not on the same domain.
I have tried to set up local users on both machines and set up the app pool to use the local accounts and I get
System.UnauthorizedAccessException: Access to the path is denied.
and
401 - Unauthorized: Access is denied due to invalid credentials.
You do not have permission to view this directory or page using the credentials that you supplied.
I have set the virtual to connect as the local user and get the same error.
I have setup a domain user and then set the app pool to use the domain user and set to use pass through and when I test the settings in Directory Browsing it says everything is good but I get the same error from the webpage.
I have setup a domain user and then set the app pool to use the domain user and set to the connect as to the user and when I test the settings in Directory Browsing it says everything is good but I get the same error from the webpage.
I have set the apppool to use my login and it works with pass through permissions.
Is there something I am missing.

You need to set the folder permissions in your separate folder to give access to the "computer$" account of the server where your application is hosted.
See here: https://www.iis.net/learn/manage/configuring-security/application-pool-identities
application pool identities also use the machine account to access
network resources.
So in the server where you have your data files you should set the folder permissions to allow access to the machine name where your website is hosted.

I had this same challenge when deploying a web app using IIS on a Windows 2012 Server.
The issue was the App Pool Account did not have Full rights to the Website Root.
All I had to do was to go to the directory where the Website Root resides and then right-clicked on it. Next, I selected Security and then gave the IIS-Users group full access to the directory.
For me IIS-Users group contains all Users/App Pool Accounts that are created in IIS.
That's all.
I hope this helps

I have created a domain user specifically for the the virtual directory and it appears to work, but is this best practice?

Related

ASP.NET Access Denied error when trying to write into Network Folder

I've a requirement of writing into a network folder from ASP.NET.
So I just used Streamwriter class and it works fine when trying from local system using Visual studio web server. But when trying to host it into IIS on the same machine writing into network folder not working at all.
It saying
Access to {\MYSERVER\specialfolder} is denied
So I thought it as some access issue. What I tried was as follows
Changed Default Applicaiton Pool (Which is the pool using for my
domain) identity to local system (And tried the other 4 ones too) :
Still the error
Authentication change for my site. Change from
Anonymous for specific user IUSR into Application pool Identity : No
help
Right clicked on my site and then selected edit permission, then
specified write permission for IIS_IUSRS group : Not worked
Also I tried, Right Click on the network folder itself -> security ->
But there is not IIS_IUSRS group
What else I'm missing for having the write permission into network
folder.
Details about my system
IIS 8.5
WINDOWS SERVER 2012R2
VISUAL STUDIO 2015
As far as I know, the IIS use the LOCAL user which generated by the IIS, this is local computer account.
If you want to access another network folder, you should set the enough permission to the IIS application pool identity.
You should use AD to assain enough permission to a spcial AD account.
Alternatively, using ActiveDirectory you could create a Domain User account, configure the application pool identity to use that domain user, and grant that user access to the network files.
More details, you could refer to below article:
http://www.iis.net/learn/manage/configuring-security/application-pool-identities

Unable to access virtual directory that points to a networked share

I have a .NET 4.61 website running in IIS on Windows Server 2016. The website is bound to an app pool. I've created a domain account which serves as the Identity for this app pool.
The website has a virtual directory in it called images. This virtual directory points to a networked resource.
If I click Test Settings... button, everything works great:
However, if I access the site from the browser: http://10.10.121.11/images/someresource.htm, I get
401 - Unauthorized: Access is denied due to invalid credentials.
You do not have permission to view this directory or page using the credentials that you supplied.
Now if I go into Advanced Settings for the imagesvirtual directory and change the Physical Path Credentials to Specific User (instead of pass-through authentication) and enter the same exact user as I've entered for the app pool, everything works fine. But I shouldn't have to do that. Shouldn't the virtual directly inherit the app pool identity?
What am I missing?

Access Denied to different server on Virtual Directory in IIS

I setup an asp.net web application on IIS that I have setup several times for other clients but getting a strange permission issue on this one.
It's setup so the App Pool Identity is NetworkService and the folder being used has Network Service as a permitted user with full permissions. The folder can be browsed from the server the application is on and items added, edited and deleted.
But for a reason I cannot determine any time the application tries to access a file from the virtual directory I get 'Access is Denied'. I have checked permissions on the root folder of the actual application which also has Network Service and checked the virtual directory permissions use the identity as well, not sure what else to try?

Error 500.19 - IIS 7.5 Site based on UNC - File Permissions Problem

I'm trying to get a website in my IIS 7.5 (Win 7 Pro machine) to run via a UNC path to the code for one of the default website and an underlying App. This is the first time I've ever tried to set up a site/app in IIS 7.5 based off a UNC path: a folder on another server in the same domain.
I've tried various things to try to get this resolved. The app pool is running under ApplicationPoolIdentity on my Win 7 Pro PC where I have this site set up.
The runtime error I get when trying to run the app in the browser via http://localhost/TheAppName is:
Module: IIS Web Core
Notification: Unknown
Handler: Not Yet Determined
Error Code: 0x800700005
Config Error: Cannot read configuration file due to insufficient permissions
Config File: \\?\UNC\theServerName\www\TheAppName
Requested URL: http://localhost:80/TheAppName
Physical Path: (nothing showing up here)
Logon Method: Not yet determined
Logon User: Not yet determined
I put in fake names for the server and app name above for privacy for this post.
So it's having trouble reading the web.config found in that UNC path for this site.
I tried to add a local user on the target server and then then gave that user permissions to the web.config and then used that user RemoteServerName\LocalUserICreated as the app pool's Identity on my machine but it had no effect.
No clue what to do here and how to go about it.
I assume the UNC path is to a different server?
If so are both servers in the same domain? If so then IIS needs to run the website under a user account that has permissions to read the files.
If not you need to create identical user accounts (same username, same password) on the web server and the file storage server and then change IIS to run the website under this user account.
Hope this helps/works.
When you create a web application or virtual directory from a UNC path, you need to provide the credentials to IIS for the connection.
In the Add Application dialog, below the Physical path section is the "Connect as..." button - you can then choose either "Application user (pass-through authentication)" or "Specific user".
Which ever you choose, they have to be credentials that will be recognised by the remote server - "Pass-through" will try and use the current desktop (or browser) credentials to authenticate the user which (if you're connecting via a VPN as per your comments) almost certainly won't be valid. In this case you should use "Specific user" and provide (ideally) a domain user with suitable permissions to run the site.
When we've needed to do this in the past, we'd create an account on the domain that the local AppPools would run under, and then this could be used in these situations as well.
If you've already created the application, the dialog can be reached using the "Basic Settings..." action link.
I took me a few hours to finally solve the same issue for myself. Turned out I used the wrong slashes in my physical path. It should be \ these, not // these.
Zhaph and Alan both identify the work-around suggested by Microsoft. Here's the rest of the information from Microsoft's page on your problem:
Cause
IIS 6.0 uses the hosting worker-process identity to connect to a remote directory. Then, IIS 6.0 authenticates the user against the remote directory. However, IIS 7.0 introduces delegation scenarios. In IIS 7.0, you can delegate Web-site settings and application-level settings to a Web.config file.
For pass-through authentication, the Web.config file is stored in a UNC directory. Therefore, the default-process identity in IIS 7.0 must examine the Web.config file first to determine whether any security-related settings must be applied before the authentication process starts. The default-process identity in IIS 7.0 does not have sufficient permissions to open the Web.config file. Therefore, the Web request is rejected.
If there is no Web.config file in the UNC directory, IIS 7.0 uses the rules that are defined for the parent directory. For the Web content to be served in this scenario, the worker-process identity must have access to the whole content directory. Otherwise, the Web request is rejected.
Resolution
To resolve this behavior and to make sure that pass-through authentication works correctly, follow these steps:
Make sure that all the user accounts that access the UNC directory have at least the Read permission for the UNC directory.
Note This behavior is the same as the behavior in IIS 6.0.
Make sure that the IIS worker-process identity is running under a domain account or under a workgroup account that also exists on the UNC file server. If it is necessary, create an account on the UNC file server that has the same user name and the same password as the IIS worker-process identity.
Notes
This behavior differs from the behavior in IIS 6.0.
By default, the DefaultAppPool application pool runs under the Network Service account. This account is local to the computer, and this account does not exist on another computer. Therefore, make sure that you configure the DefaultAppPool application pool to use an account that is a domain user. Then, you can use the same account on the UNC file server. Alternatively, you can create a workgroup account on the UNC file server and on the computer that is running IIS 7.0.
If there is a Web.config file in the UNC directory, edit the discretionary access control list (DACL) for the Web.config file so that the DACL contains the account that you verified in step 2. Alternatively, edit the DACL for the Web.config file so that the DACL contains the account that you created in step 2.
If there is no Web.config file in the UNC directory, edit the DACL for the UNC directory so that the DACL contains the account that you verified in step 2. Alternatively, edit the DACL for the UNC directory so that the DACL contains the account that you created in step 2.
Note This behavior differs from the behavior in IIS 6.0.

asp mvc textreader

I am trying to use a textreader to retrieve data from a text file on a local machine. I have an upload routine to get the file for the reader to open.
When I run the application locally, it works fine. When I publish my application to my server, I am getting a Could not find a part of the path error. I assume this error has to do with permission in that the server cannot read from the local file system, but I don't know the proper way to remedy this.
do I set up the application to impersonate the user? I know I can't possibly set up each local users machine to allow the iusr account to access it.
Thanks for any thoughts.
UPDATE ****
I ensured that network service is they user for the app pool. I also ensured that the networkService has access to the local folder that the application resides in. I am running IIS7, and when I test the site, I am getting the error -
The server is configured to use pass-through authentication with a built-in account to access the specified physical path. However, IIS Manager cannot verify whether the built-in account has access. Make sure that the application pool identity has Read access to the physical path. If this server is joined to a domain, and the application pool identity is NetworkService or LocalSystem, verify that <domain>\<computer_name>$ has Read access to the physical path. Then test these settings again
I have tried suggestions from various posts, including adding domain\servername$ to the folder to allow access, but nothing seems to work.
Any thoughts?
Assuming this is IIS 6.5 or higher, the application pool user must have the necessary permission. By default, this is Network Service, which likely does not.
I solved this issue by first saving the file to the server, and then accessing the server's local file -
savedFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Path.GetFileName(file.FileName));
file.SaveAs(savedFileName);
The following blog helped me out - http://www.hanselman.com/blog/default.aspx?date=2008-06-28

Resources