Search code examples
c#asp.netasp.net-core.net-coreasp.net-core-mvc

How to configure multiple ASPNETCORE_ENVIRONMENT on same machine?


I have ASP.NET core web application. I have configured the web application on our web server and set the ASPNETCORE_ENVIRONMENT variable to Development. I set this variable at machine level like shown in the picture below. Now on the same machine i want to configured one more instance of same web application as Staging environment.

What are my options here to set ASPNETCORE_ENVIRONMENT at application level instead of machine level? so i can host multiple instances of the same application on the same machine?

enter image description here

enter image description here


Solution

  • You have a couple of options.

    1. Run each app as a different user, and set the environment variable within that user profile. This gives you a nice added security bonus. You'll have to set the app pool to load the user profile.

    2. Use IIS configuration

      1. Start IIS manager
      2. Choose configuration editor Pull down the section combobox and choose system.webServer/aspNetCore
      3. Pull down the from combobox and choose Applicationhost.config
      4. Click on the environmentVariables element and click on the ... button hiding in the second column, at the right.
      5. Set your environment variables.
      6. Exit out of the environment variables screen and then click Apply.
      7. Restart the app pool/app.