I have two web sites on my staging server, and both are ASP.NET Core sites that run in IIS. I have set the environment variable ASPNETCORE_ENVIRONMENT
to Staging
machine-wide. This works well for one of the sites, however the other ignores the variable and runs in production mode instead. I have to configure the hosting environment into the web.config
file to run it in staging mode.
Why does one site not take the environment variable into account?
In both of my Startup(IHostingEnvironment env)
constructors, I use the environment variables:
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddJsonFile("logging.json")
.AddEnvironmentVariables(); // <---
Configuration = builder.Build();
}
appsettings.Staging.json
on either site. ASPNETCORE_ENVIRONMENT is set machine-wide. Startup logging for second site logs: "Environment: Production". – Agony[09:20:33 INF] ASPNETCORE_ENVIRONMENT = '' Hosting environment: Production
when starting via IIS,[08:56:07 INF] ASPNETCORE_ENVIRONMENT = 'Staging' Hosting environment: Staging
when starting stand-alone directly on console. – Agony