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

前端 未结 12 1870
时光取名叫无心
时光取名叫无心 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:51

    Since there is no full copy & paste solution yet, based on Joe Audette's answer:

    public IWebHostEnvironment Environment { get; }
    
    public Startup(IWebHostEnvironment environment, IConfiguration configuration)
    {
       Environment = environment;
       ...
    }
    
    public void ConfigureServices(IServiceCollection services)
    {
       if (Environment.IsDevelopment())
       {
           // Do something
       }else{
           // Do something
       }
       ...
    }
    

提交回复
热议问题