My site is running under IIS among a dozen others. I want to set its hosting environment to Staging, but I can’t use ASPNETCORE_ENVIRONMENT environment variable to set it, because of the aforementioned other sites.
How can I set the hosting environment for a specific site.
P.S. Found the documentation that addresses this specific scenario. The short story is change web.config (yes, the legacy file).
>Solution :
While it is not easy to find, but when Microsoft documented ASP.NET Core module they did provide sample code on how to set environment variables in web.config, so there is no need to follow the other answer to modify applicationHost.config.
<aspNetCore processPath="dotnet"
arguments=".\MyApp.dll"
stdoutLogEnabled="false"
stdoutLogFile=".\logs\stdout"
hostingModel="inprocess">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
<environmentVariable name="CONFIG_DIR" value="f:\application_config" />
</environmentVariables>
</aspNetCore>
It is the same web.config generated by dotnet publish, so I believe you feel natural that further changes go to the same place.
Another way you might want is to configure such environment variables on the application pool.