Assigning File Permission For ApplicationPoolIdentity in IIS 8
Everything was going fine after publishing a new web application to IIS 8 on Windows Server 2014. Then suddenly I saw few errors in logs like:
System.UnauthorizedAccessException Access to the path 'C:\inetpub\wwwroot\wodnerful-app\reports\Q1 2017.pdf' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode) at WonderfulApp.Controllers.Api.Reports.d__4.MoveNext()
The files were under root application folder. The application was running under ApplicationPoolIdentity in its own application pool.
I checked the permissions on folder for following principals/groups:
IIS_User
IUSR
Authenticated Users
Network Service
Well, all had the read and execute permissions.
Clearly the ApplicationPoolIdentity under which the website was running was not (or part of) anyone of the above.
I looked at it in Task Manager and it showed WonderfulApp as user running this (w3wp.exe) process.
It seemed straightforward at this point: go to the folder, right-click select Properties>Security>Advanced>Add>Select a principal> type user name in the box and click Check Names button.
But whatever I did, it was not getting the WonderfulApp user/principal that was shown in Task Manager.
After fiddling around and googling about it, I stumbled upon this answer on Severfault. It required to type IIS APPPOOL Yep those are 3 Ps before the WonderfulApp like this: IIS APPPOOL\WonderfulApp.
Giving appropriate permissions to IIS APPPOOL\WonderfulApp made it work
So in short, if your app is running under ApplicationPoolIdentity and you are not impersonating, your user name should be IIS APPPOOL\ApplictaionPoolName
Happy Coding!













