【问题标题】:How can I represent a json array in an Environment Variable for aspnet vnext configuration如何在 aspnet vnext 配置的环境变量中表示 json 数组
【发布时间】:2016-07-01 10:10:55
【问题描述】:

我的 appsettings.json 文件中有以下部分用于我的 aspnet vnext 应用程序。

"Settings": {
    "IgnoredServices" : ["ignore1", "ignore2"]
  }
}

这在使用设置类所在的IOptions<Settings> 映射时非常有效

public class Settings
{
    public List<string> IgnoredServices { get; set; } 
}

但是,我正在努力用环境变量形式覆盖这个 json 文件选项。我试过了

名称 Settings:IgnoredServices
值 "ignore1", "ignore2"

和

名称 Settings:IgnoredServices
值 ["ignore1", "ignore2"]

似乎都没有正确映射,我收到以下错误消息

System.InvalidOperationException: Failed to convert '["ignore1", "ignore2"]' 
to type 'System.Collections.Generic.List`1[System.String]

我应该将我的值以什么格式放入环境变量中才能成功解释为正确的字符串列表?

【问题讨论】:

  • 我还尝试将 JSON 设置部分存储在环境变量中。从表面上看,我们做不到。我们必须为每个设置单独创建独立变量,然后单独提取那些对我来说也很笨重的变量。

标签: json environment-variables asp.net-core


【解决方案1】:

试试这个:

姓名 Settings:IgnoredServices:0

价值 ignore1

姓名 Settings:IgnoredServices:1

价值 ignore2

【讨论】:

    猜你喜欢
    • 2015-02-11
    • 1970-01-01
    • 2019-02-17
    • 2022-06-11
    • 2014-08-05
    • 2019-07-29
    • 1970-01-01
    • 2017-05-24
    • 1970-01-01
    相关资源
    最近更新 更多