I would like to use environment variable in my web application.
I go to the advanced system settings and set my environment variable (for example MY_HOST_NAME) by system-level variables. Then I restart the server and check with the commandline "set" if the variable is there and I can see it. But if I try to get the variable within my application which is hosted by IIS, there is the variable null. The code which I'm using:
var host = Environment.GetEnvironmentVariable("MY_HOST_NAME");
Knows anyone where the problem could be or how can I find the bug?
If by restarting server you mean Restart from IIS Manager, then this will not be enough. In case you don't want to restart the machine (who does?), you'll have to restart iis from an elevated prompt to pickup the newly changed variables
iisreset /restart
or in case one prefers some more typing
net stop w3svc && net start w3svc
Is it a user environmental variable, or a system-level variable? The reason I ask is your IIS code is probably running as a different user. If your variable is a user variable, it wouldn't be present when the code runs as the other user.
Go to the control panel, system properties:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With