I would like to set an environment variable that should only be available to a specific ASP.NET web application running in IIS 10. I came upon Setting environment variables for asp.net core when publishing on IIS, but I have an ASP.NET application (.NET framework) not .NET Core.
I did try what they said to do anyhow:
- Open IIS Manager
- Navigate to my specific web application under "Default Web Site"
- Click on "Configuration Editor" under the "Management" heading
- Load the configs from
system.webServer/aspNetCore - Added my environment variable
- Restarted IIS
From C#, I attempted to get the value of this environment variable using:
Environment.GetEnvironmentVariable("NAME_HERE");
And it came back null. Even after rebooting my Windows 10 laptop I was still getting a null value.
How can I set an environment variable so only a specific IIS application/virtual directory has access to it?