I need to set the environment variable COMPLUS_FORCEENC=1
in an ASP.NET application. This variable must be set at the time the worker process starts to have an effect.
Therefore, I did this:
- Create a new user using the Computer Management console.
- Set a password.
- Make sure it is a member of
Users
andIIS_IUSRS
. - Configure the IIS Application Pool to use that user and load the user profile. This is using a custom pool, not the default one.
- Log in as that user to set the variable.
- Relogin to make sure the variable is set.
- Restart the OS.
- Make sure the application loads and works.
Unfortunately, the ASP.NET app does not see the variable. I printed the whole environment from within the app.
When I use Process Explorer on the worker process I see that it runs under the correct user but the variable is not set. Also, the TEMP
variable points to C:\Windows\Temp
and not (as expected) to the user profile's temp directory (which exists). I understand this is a sign of the user profile not being loaded.
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\hivelist
shows the hive of that user loaded. The Environment
key for that user appears to be populated correctly:
What did I do wrong? How can I make the variable appear?
This is a Windows 7 machine.
So, for Windows 7 SP1 you additionally need to edit the following file:
and add a
processModel
element withsetProfileEnvironment
set totrue
for your site app pool in theapplicationPools
section.It should look like this:
See Windows 7 SP1 causes IntelliTrace Collection to fail on IIS for more details.
Note: You should edit the
applicationHost.config
file with admin rights and after the change you should reboot the computer.Just set/create the environment variable within an asp.net page
like:
this should survive AppPool recycles and even server reboots.
I have a full working example at this answer