ApplicationPoolIdentity Environment variables IIS
Is it possible to set Environment Variables for ApplicationPoolIdentity virtual accounts? The documentation on this is practically-non existent.
I would like to inject an Environment Variable for just that Application Pool. It seems to be the case that people create unique accounts for the app pool to do this, but what I've read about virtual accounts implies I wouldn't have to, but doesn't explain at all how to do this.
Solution 1:
Yes! (As long as you're using IIS 7.0+) You need to set the loadUserProfile
setting for the Application Pool Identity to true. The Application Pool Identity will now have a user profile under \Users\[Application Pool Name]. You can then edit this profile to have custom environment variables, etc.
IIS 7 Tip # 3 You can now load the user profile of the application pool identity
EDIT: I just tested this (in IIS 10), because of your comment, and it's definitely working here.
- In IIS, I created a new Application Pool named
Testing
- I changed the Application Pool Defaults to set Load User Profile to
True
- I started the Application Pool, Testing
- I checked to see if the user profile was created at \Users\Testing: no
- I added a website to the Application Pool and restarted the website
- I checked again to see if the user profile was created: still no
- I navigated to the website in my browser, so the application pool would load
- I checked a third time to see if the user profile was created: yes
- I checked to see if the user registry was loaded in
HKEY_USERS
, (by checkingHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\hivelist
to see whether theNTUSER.DAT
file located at[...]\Users\Testing\NTUSER.DAT
was loaded, and it was, with SIDS-1-5-82-454248297-962034619-2554273252-202815998-4121577539
) - I checked for the presence of the
HKEY_Users\[SID]\Environments
key, it's present, and has valuesTEMP
andTMP
pointing to%USERPROFILE%\AppData\Local\Temp
.
The reason I had to do a page load is because I forgot to change the Start Mode
from OnDemand
to AlwaysRunning
. When I created another Application Pool with Start Mode
set to AlwaysRunning
, the user profile was created when I assigned a web site to the Application Pool and restarted the website.
More useful information on Application Pool Identities: Application Pool Identities