ASP.NET Core hosting environment variable ignored

前端 未结 5 742
梦毁少年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:01

    public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
    
            if (env.IsDevelopment())
            {
                // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
                builder.AddUserSecrets();
            }
    
            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
        }
    

    You might not have added variable builder.AddEnvironmentVariables();

提交回复
热议问题