How to set Environment Name (IHostingEnvironment.EnvironmentName)?

后端 未结 11 955
耶瑟儿~
耶瑟儿~ 2020-12-04 16:06

Default ASP.NET Core web project contain such lines in Startup.cs:

if (string.Equals(env.EnvironmentName, \"Development\", StringComparison.Ordi         


        
11条回答
  •  爱一瞬间的悲伤
    2020-12-04 16:53

    Here is one more way to set and switch ASPNETCORE_ENVIRONMENT variable in VS2017 (addtional note to @clark-wu answer):

    Note: launchSettings.json has two profiles in my case: "IISExpress" and "Project" where ASPNETCORE_ENVIRONMENT is defined.

    {
      "iisSettings": {
        "windowsAuthentication": false,
        "anonymousAuthentication": true,
        "iisExpress": {
          "applicationUrl": "http://localhost:10000/",
          "sslPort": 0
        }
      },
      "profiles": {
        "IIS Express": {
          "commandName": "IISExpress",
          "launchBrowser": true,
          "launchUrl": "api/entities",
          "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development" // <-- related to IIS Express profile
          }
        },
        "Project": {
          "commandName": "Project",
          "launchBrowser": true,
          "launchUrl": "api/entities",
          "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Production" // <-- related to Project profile
          },
          "applicationUrl": "http://localhost:10000/"
        }
      }
    }
    

    Official documentation: You can set ASPNETCORE_ENVIRONMENT to any value, but three values are supported by the framework: Development, Staging, and Production. If ASPNETCORE_ENVIRONMENT isn't set, it defaults to Production.

提交回复
热议问题