如何在环境变量中覆盖appsettings.json中基于数组的设置?

问题描述 投票:0回答:1

我在appsettings.json中有以下配置

"AvailableThemes": {
    "DefaultThemeKey": "abt",
    "Themes": [
      {
        "ThemeKey": "xc",
        "ThemeTitle": "XC 13"
      },
      {
        "ThemeKey": "abt",
        "ThemeTitle": "Taxis"
        "RegistrationSupported": true,
        "IntroText": "Hello",
      }
    ]
  }
}

我需要能够覆盖环境变量中的RegistrationSupported,以便我可以部署禁用注册的站点,并在链接站点上线时启用它。

AvailableThemes:主题:RegistrationSupported

但这不起作用,因为它不知道要覆盖哪个项目。我试过像这样的索引器......

AvailableThemes:主题[1]:RegistrationSupported

......哪些不起作用。

asp.net azure .net-core
1个回答
1
投票

发布后几乎直接找到答案。 Indexer是正确的方法,但语法错误。

它应该没有方括号......

AvailableThemes:主题:1:RegistrationSupported

完整的文章在这里 - How to override an ASP.NET Core configuration array setting using environment variables

© www.soinside.com 2019 - 2024. All rights reserved.