0

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?

mituw16
  • 5,126
  • 3
  • 23
  • 48
  • `The following sections have been defined but have not been rendered for the layout page “~/Views/Shared/_Layout.cshtml”` could you share a section and your _Layout.cshtml? – Set Jul 31 '17 at 16:50
  • I can, yes.. but that shouldn't make a difference as the entire application is working perfectly in 3 / 4 environments with zero code changes between them, – mituw16 Jul 31 '17 at 16:51
  • sorry, but right now this looks like off-topic as we cannot reproduce your problem and right now all looks like you have some code that is not executed for `DeployDev ` env. In provided code, the only difference is `options.IsDev = true;` but you say that is works on Production well. – Set Jul 31 '17 at 17:06

1 Answers1

0
else if (Environment.EnvironmentName.ToLower() == "DeployDev")

this is your problem. You use ToLower() so you should compare Environment name with "DeployDev".ToLower() equavalent:

else if (Environment.EnvironmentName.ToLower() == "deploydev")
Set
  • 47,577
  • 22
  • 132
  • 150
  • That is a good catch, however it doesn't appear to solve my problem. I changed the code to do as you suggested, but still get the original error. – mituw16 Jul 31 '17 at 16:48