How to get the Development/Staging/production Hosting Environment in ConfigureServices

前端 未结 12 1853
时光取名叫无心
时光取名叫无心 2020-12-04 15:51

How do I get the Development/Staging/production Hosting Environment in the ConfigureServices method in Startup?

public void ConfigureServices(IS         


        
12条回答
  •  既然无缘
    2020-12-04 16:27

    The hosting environment comes from the ASPNET_ENV environment variable, which is available during Startup using the IHostingEnvironment.IsEnvironment extension method, or one of the corresponding convenience methods of IsDevelopment or IsProduction. Either save what you need in Startup(), or in ConfigureServices call:

    var foo = Environment.GetEnvironmentVariable("ASPNET_ENV");
    

提交回复
热议问题