This is a really really strange one. If I make a change to the ASPNETCORE_ENVIRONMENT
server variable in IIS, it sometimes breaks my application.
Everything works great on my local machine, production, and demo environments. I wanted to add an additional dev environment where I could test stuff, but have it actually be on our servers vs. debugging in visual studio.
I have my Startup.cs
configured like so.
if (Environment.IsDevelopment())
{
options.ConnectionString = Configuration["Data:DevConnection:ConnectionString"];
options.BaseUrl = Configuration["EnvironmentUrl:Dev:Url"];
options.IsDev = true;
}
else if (Environment.EnvironmentName.ToLower() == "demo")
{
options.ConnectionString = Configuration["Data:Demo:ConnectionString"];
options.BaseUrl = Configuration["EnvironmentUrl:Demo:Url"];
}
else if (Environment.EnvironmentName.ToLower() == "deploydev")
{
options.ConnectionString = Configuration["Data:DeployDevConnection:ConnectionString"];
options.BaseUrl = Configuration["EnvironmentUrl:DeployDev:Url"];
}
else
{
options.ConnectionString = Configuration["Data:ProdConnection:ConnectionString"];
options.BaseUrl = Configuration["EnvironmentUrl:Prod:Url"];
}
My appsettings.json
is set up accordingly. In this exact configuration, all of the different environments work, except DeployDev
.. (All of the environments, other than my local machine, are IIS 7.5 on Windows Server 2008R2 that are clones of each other).
The error I get on DeployDev
is The following sections have been defined but have not been rendered for the layout page “~/Views/Shared/_Layout.cshtml”
Weird right? There are no code / server config changes between any of the environments other than me adding an environment variable on DeployDev
called DeployDev using the process laid out here. https://stackoverflow.com/a/36836533/1729859 (I did the exact same thing for demo, and it works fine).
So continuing down the rabitt hole and many head scratches, I had the thought to try changing the environment variable on my DeployDev
instance to something else. I changed it to Staging
and updated my code to look for else if (Environment.EnvironmentName.ToLower() == "Staging")
, but left everything else the same. To my suprise, everything started working perfectly.
So to recap, I made no code changes / environment changes, only changed the environment variable from DeployDev
to Staging
and voila, everything works. WEIRD!! Has anyone seen this before? Should I send this to the .net core team on github?