ASP.NET Core hosting environment variable ignored

前端 未结 5 738
梦毁少年i
梦毁少年i 2020-12-31 03:20

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

5条回答
  •  [愿得一人]
    2020-12-31 04:12

    I just spent the last couple hours dealing with the same issue. I'm not sure if the result will be the same since you seem to have one of two applications working.

    I set the ASPNETCORE_ENVIRONMENT to "Staging" as a system variable through "Advanced System Settings" on Windows Server 2008 R2 and always ended up in the "Production" environment (which is the default environment if it can't find the setting anywhere).

    Using "set" from Command Prompt showed the expected results of "ASPNETCORE_ENVIRONMENT=Staging".

    Calling Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") returned null. I created another variable called "Test" which also returned null. Calling any other existing variable returned expected results.

    I tried recycling the application pool, changing the app pool's user, restarting IIS through management console, even restarting World Wide Web Publishing Service (probably same as reset in IIS mgmt console) all to no avail.

    Rebooting the server was the only way I could get the application to return the expected result.

提交回复
热议问题