About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.
The site loads, but saving an upload, writing a log or reading a file on a share fails with an access denied error. In a .NET app this shows up as an UnauthorizedAccessException. In the usual case, the account being refused is not the person using the site and not the administrator who deployed it. It is the identity IIS runs the site's worker process under. An app set up to impersonate the signed-in user, or a site that uses a separate anonymous user account, runs file access under that account instead, so check the app's settings if the pool identity already has access.
What you see
- An
UnauthorizedAccessExceptionin the app's error page or log. Microsoft describes it as the exception thrown when the operating system denies access because of an I/O error or a specific type of security error. It uses HRESULT 0x80070005 (Microsoft Learn, UnauthorizedAccessException). - It happens when the app reads or writes a particular folder, such as an uploads folder or a file on a network share, while the rest of the site works.
- The same action may work when run as an administrator on the server. It follows from the cause below that the administrator's account has rights the application pool's account does not.
Why it happens
Since IIS 7.5, every new application pool runs as its own application pool identity by default. IIS creates a virtual account named after the pool, such as IIS AppPool\DefaultAppPool, and runs the pool's worker processes (W3wp.exe) under it. It is not a real user account and does not appear in Windows user management, but files and folders can be secured for it (Microsoft Learn, Application Pool Identities).
The access is refused for one of these reasons:
- The folder has no permission for the pool's identity. Microsoft's ASP.NET Core hosting page says Read & execute should be granted by default, and that the pool needs read and write access to folders where the app reads and writes files (Microsoft Learn, Host ASP.NET Core on Windows with IIS).
- Permissions were set for the old identity. Microsoft says the biggest compatibility issue is older guidance that told you to grant access to Network Service, the default before IIS 7.5. Those folders need access for
IIS AppPool\<pool name>instead. - The pool's identity was changed to another account that lacks rights to the app's folder, database or other resources.
- The resource is on another server. With the default ApplicationPoolIdentity, the pool uses the server's computer account on the network, in the form
<domainname>\<machinename>$. A file share must allow that account, notIIS AppPool\<pool name>. If the pool runs as a named domain account, the share must allow that domain account instead. - The file itself refuses the write. Microsoft's .NET reference lists, for writing a file, a read-only file, a hidden file, or a path that is a folder, as well as the caller lacking the required permission (Microsoft Learn, File.WriteAllText).
- The app expects a user profile. IIS does not create a user profile for new application pools. Microsoft says some applications store temporary data in a profile, and gives SQL Express as an example.
How to prove the cause
1. Find the identity. In IIS Manager, open Application Pools, select the site's pool, open Advanced Settings and read Identity under Process Model. ApplicationPoolIdentity means the account is IIS AppPool\<pool name>.
2. Read the exact path from the error. Microsoft advises reading the exception's message to find the reason. Note the full path and whether it is local or on a share.
3. Show the folder's permissions. Microsoft describes icacls as displaying or modifying access lists; given only a path, it displays them (Microsoft Learn, icacls):
icacls C:\sites\MyWebApp\uploads
Look for the pool's identity, or a group it belongs to, with the access the app needs. Inherited entries are marked (I).
4. For a share, check the computer account. Check that both the share and the folder allow <domainname>\<machinename>$.
5. Rule out the file itself. Check whether the file is read-only or hidden, or whether the path names a folder where the code expects a file.
The fix
Grant the pool's identity on the folder it uses. In Windows Explorer, open the folder's Properties, then Security, Edit, Add. Select Locations and choose the local computer. Type IIS AppPool\<pool name> and select Check Names. Microsoft notes that you cannot type the pool name alone; use the IIS AppPool\ form. Then grant the access needed.
Microsoft's examples use icacls and grant full access:
ICACLS C:\sites\MyWebApp /grant "IIS AppPool\DefaultAppPool":F
Full access is more than most apps need. The icacls syntax also allows M (modify) or RX (read and execute), and (OI)(CI) so files and subfolders inherit the entry. Built from that syntax, not a Microsoft example, a write grant on just the uploads folder of a pool named MyAppPool is:
icacls "C:\sites\MyWebApp\uploads" /grant "IIS AppPool\MyAppPool:(OI)(CI)M"
Keep the rest of the site at Read & execute, as Microsoft's hosting page describes.
For a network share, grant the computer account (default ApplicationPoolIdentity), or the pool's domain account if it runs as one. Give that account the access it needs on the share and on the folder behind it.
If you changed the identity on purpose, grant that account access to the app's folder, database and other resources, as Microsoft's hosting page says.
If the app needs a profile, set the pool's Load User Profile setting (LoadUserProfile) to true.
How to confirm the fix
- The same action in the app, such as the same upload, now succeeds.
icaclson the folder listsIIS AppPool\<pool name>with the access you granted.- The app's log shows no new
UnauthorizedAccessExceptionfor that path.
What to watch afterwards
- Renamed or new pools. It follows from the identity being named after the pool that a renamed pool, or a site moved to a new pool, needs the grant again.
- Folders replaced by a deployment. It follows that an entry set directly on a folder is lost if a deployment deletes and recreates that folder.
- Restores and migrations. It follows from IIS creating the pool's identifier on each server that a restored or migrated site needs its grants checked.
Read next
Related articles you may want next.
- HostingIIS application pools: recycling, idle time-out and start mode for business web applicationsHow IIS application pool settings can cause slow first requests or loss of worker-local session data, when that can affect sign-in, and how to investigate recycling, the 20-minute idle time-out, on-demand start and Application Initialization.Read article
- TroubleshootingIIS HTTP Error 500.19 "The requested page cannot be accessed": read the error code, then the configHTTP Error 500.19 means IIS could not use the site's configuration. The HRESULT code in the error tells you which of Microsoft's documented causes you have: bad XML, a locked section, permissions, a duplicate entry, or a missing module.Read article
- Backup & RecoveryRestoring files with their permissions: SIDs, cross-domain restores and orphaned access entriesUnderstand SIDs, restored accounts, NTFS permissions, SID history, ownership and auditing when restoring files across Windows environments.Read article
Risks and limits
- Do not grant Everyone or make the pool an administrator. Microsoft's identity page explains that a low-privileged account is good practice, because a software bug then cannot be used to take over the whole system. It follows that granting broad access to fix one folder undoes that protection.
- Full access lets the app change permissions. Microsoft's examples grant
F. It follows that the app could then change the folder's own permissions; preferMorRXon the specific folder. - icacls
/grant:rreplaces explicit grants for that account rather than adding to them; plain/grantadds. - A pool set to another identity type only has the pool's identifier added to its access token. Microsoft says content can still be secured for the pool, but the token's owner is probably not unique.
- A 500.19 error, rather than access denied in the app, means IIS could not read the configuration itself. That is a different problem.
Sources
- Microsoft Learn, "Application Pool Identities", last updated 14 June 2022: https://learn.microsoft.com/en-us/iis/manage/configuring-security/application-pool-identities
- Microsoft Learn, "Host ASP.NET Core on Windows with IIS", last updated 22 July 2026: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/
- Microsoft Learn, "icacls", last updated 9 June 2025: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/icacls
- Microsoft Learn, "UnauthorizedAccessException Class": https://learn.microsoft.com/en-us/dotnet/api/system.unauthorizedaccessexception
- Microsoft Learn, "File.WriteAllText Method": https://learn.microsoft.com/en-us/dotnet/api/system.io.file.writealltext
Next step
The account that needs access is the application pool's identity, or the server's computer account for a share: grant it only what the app needs, on only the folder it uses. NetLeverage has looked after business servers since 2002. If the error remains, talk to us through managed support with the full path from the error and the pool's identity setting.
This article was originally published on .