How to set environment variable for specific IIS application?

Viewed 4586

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:

  1. Open IIS Manager
  2. Navigate to my specific web application under "Default Web Site"
  3. Click on "Configuration Editor" under the "Management" heading
  4. Load the configs from system.webServer/aspNetCore
  5. Added my environment variable
  6. 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?

0 Answers
Related