How to grant rights properly to a folder on IIS 7.5 Express - asp.net

I'm getting a quite common exception: Access to the path 'C:\inetpub\wwwroot\Content\Images\Uploads\<there goes my hashed guid as a subfolder name which is created dynamically>'
I'm using IIS Express 7.5. I'm using WA authentication in my application. Impersonation's disabled both in web.config and on IIS.
I looked at application pool the site is running (which is ASP.NET 4.0). Application pool identity: Network Service. I have given full control rights to the Uploads folder for IIS AppPool\ASP.NET 4.0. Also did this for authenticated users. Checked I did this for subfolders.
EDIT
Helped a little http://forums.asp.net/t/984207.aspx/1
I have created the folder: C:\inetpub\wwwroot\Content\Images\Uploads. It wasn't present on my C drive before). Then I added full control permissions for Network Authority on the folder and successfully uploaded a file to the path.
So I'm just curious where should I keep my project folder? Now I keeping it on other drive, not C.
EDIT
Ok. I understood. All this is connected to my code where Server.MapPath is called.
Thanks!

You must give permission to the Uploads folder for NetworkService witch is the ASP.NET 4.0 identity.

Related

Problem with IIS for creating file on Servers Folder

I have an AspNet App (Blazor) running on IIS server.
I would like to create a txt file on the server, but it doesn't work.
I changed the AppPool identity to a domain user accound and the directories in E: have full permissions for this account.
It works in VisualStudio IIS Express, but not in IIS.
Anyone here who can help me? A permission problem`?
C# Code for creating txt file:
File.WriteAllText(#"E:\Publish\Export\Test.txt", "Hello World");
If you want to save to a specific path, use MapPath (or Server.MapPath) to get the physical path corresponding to the application. Because by default the web server (IIS or local development server) will save to its working directory.
Also you need to make sure the account running IIS has read/write permissions to the directory you need to write to. If you're looking for user accounts, go to "Advanced Settings" under Application Pools and check what's set for "Identity".

Missing site assets when no local\Users permission on the folder

I'm working on the Umbraco site (asp.net MVC) hosted on local Windows Server 2016+IIS10.
During regular template modification, I have experienced strange behavior - the site lost all of the assets hosted from local files. All the requests to cases or images were redirected to the login page. A few people reported similar behavior, commonly resolving it by permission checking. So did I - ensured that my pool user has granted full access to the folder and all its descendants. It was, so I removed it and applied it once again. Still no luck. I have copied the website files and created another web app in IIS - this one worked without any glitch.
Later, my co-worker found that the application folder is missing access permission for the local machine "Users" group. When we added it - the site is served without any issues.
The webserver is part of the corporate domain (AD) and the app pool user is a "service user".
Is it normal that it needs both - pool user and local "Users" permission?
Why is so?
It is normal. When the static file and the application are in same machine, the application needs higher permissions to read the static file.
When the application runs in IIS, it will use the identity of the application pool to read static files, and the default identity of the application pool is ApplicationPoolIdentity, with the lowest permissions.
The test in visual studio does not have this problem because IIS express runs the application with the same permissions as the administrator.

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

Web configuration file being accessed in the wrong folder

I have deployed an asp.net website on a production server. It is working on my local but on the server I get this error:
An error occurred loading a configuration file: Failed to start
monitoring changes to
'E:\HostingSpaces\xxxxx\xxxxxx.xxxxxx.com\wwwroot\admin\web.config'
because access is denied
This looks to me that the app is looking for the web.config in the admin folder while it is obviously in the root.
How is this possible? How do I solve this problem?
IIS which is hosting ASP.NET is looking for a potential web.config file in every folder of your site, not just in the root folder.
This is because you may want to override certain settings for just one folder.
So you may have a web.config in admin but IIS hasn't got access to it, or IIS hasn't got access to the whole admin folder.
Check the permissions on that directory.
The problem is that the directory it has been deployed to does not have the correct read/write permissions for IIS to read the web.config.
Each website configured in IIS 6+ runs under a specific AppPool. That app pool runs under a specific user account, and it is that user account that needs read/write permissions to this directory.

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.

Resources