When running an asp.net core website on IIS, it will default to "Production", when
ASPNETCORE_ENVIRONMENT is not set. This is actually a good default.
You could actually set the environment variable globally on the machine, but then all sites will be have the same value. So what if
Production is on the same machine ...
You can actually set it on the website in IIS.
- Open the "Internet Information Services (IIS) Manager.
- Go to the Website where you want to set the environment variable.
- Find the "Configuration Editor".
- In the "Section" to the top left of the window, select
system.webServer/aspNetCore in the dropdown and just to the right og this, REMEMBER to select
ApplicationHost.config. If you fotget, you will set this variable in the used
web.config for the running site. Then ofcause it will be overwritten when you deploy a new version of the website. The
ApplicationHost.config sets it machine level, so the setting will live in a deffenrent place. You can read more about ApplicationHost.config here
environmentVariables line and click the tree dots at the end to edit the list.
- Click the Add button and set the
- Close the window and restart the website. The website should now have the ASPNETCORE_ENVIRONMENT variable set to
Side note: Ofcause you should have different machines for each environment, but sometimes this is just not an option :-( :-( :-(