【问题标题】:ASP.NET Core Environment Variable Not Set未设置 ASP.NET Core 环境变量
【发布时间】:2016-09-12 02:30:10
【问题描述】:

我正在尝试在我的应用程序中使用环境变量,因此我不必费心维护跨不同系统的配置文件。也许我只是对这些变量的来源有一个误解。

首先,我在本地 System -> Advanced 属性上创建了一个名为 MediatrExampleDbConnection 的 Windows 系统变量

然后,我的 Startup.cs 中有这段代码:

var builder = new ConfigurationBuilder()
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
            .AddEnvironmentVariables();
        Configuration = builder.Build();

当我稍后尝试访问它时,它又回来了 null

var MediatrConnectionString = Configuration["MediatrExampleDbConnection"];

这不是应该从我的本地系统变量中提取的吗,因为我在那里有.AddEnvironmentVariables();

【问题讨论】:

    标签: c# asp.net asp.net-core


    【解决方案1】:

    好吧,我误会了。

    据此贴:Accessing environment variables from ASP.NET Core 1 RC1 IConfiguration

    这些是您的项目属性中的 Web 应用程序、环境变量:

    这些不是来自您的 Windows 系统环境变量 高级系统设置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-05
      • 2022-11-16
      • 2013-11-20
      • 2013-04-20
      • 2022-12-02
      • 2018-03-08
      • 2017-12-31
      相关资源
      最近更新 更多