【问题标题】:Azure App Service - App Settings Array In ArrayAzure 应用服务 - 数组中的应用设置数组
【发布时间】:2022-02-05 00:57:28
【问题描述】:

我目前正在尝试在 Azure 应用服务配置中创建一个“复杂”的 appsettings 结构,但我失败了。

我的 appsettings.json 看起来……像这样:

{
"AgentPools": [
    {
      "Id": "1",
      "Name": "PoolName1",
      "AllowedProjects": []
    },
    {
      "Id": "2",
      "Name": "PoolName2",
      "AllowedProjects": [
        "myproject1",
        "myproject2"
      ]
    }
  ]
}

我现在的问题是,似乎我在数组中该数组的设置中做错了什么。

Azure 应用服务 (Linux) 中的配置如下所示:

  • AgentPools__0__Id -> 1 => 工作
  • AgentPools__0__Name -> PoolName1 => 工作

  • AgentPools__1__Id -> 2 => 工作
  • AgentPools__1__Name -> Poolname2 => 工作
  • AgentPools__1__AllowedProjects__0 -> myproject1 => 不工作
  • AgentPools__1__AllowedProjects__1 -> myproject2 => 不工作

我真的做错了什么,或者甚至不可能构建一个更复杂的结构吗?

我在 netcore 中编程。

【问题讨论】:

    标签: azure azure-web-app-service


    【解决方案1】:

    this article 中的示例建议只有当数组具有对象作为嵌套属性而不是直接值时,才能覆盖数组值。

    当元素结构中包含数组时,数组索引应被视为该路径中的附加元素名称。

    {
        "SmtpServer": "smtp.example.com",
        "Logging": [
            {
                "Name": "ToEmail",
                "Level": "Critical",
                "Args": {
                    "FromAddress": "MySystem@example.com",
                    "ToAddress": "SRE@example.com"
                }
            },
            {
                "Name": "ToConsole",
                "Level": "Information"
            }
        ]
    }
    
    setx SmtpServer smtp.example.com
    setx Logging__0__Name ToEmail
    setx Logging__0__Level Critical
    setx Logging__0__Args__FromAddress MySystem@example.com
    setx Logging__0__Args__ToAddress SRE@example.com
    setx Logging__1__Name ToConsole
    setx Logging__1__Level Information
    

    【讨论】:

      猜你喜欢
      • 2018-10-16
      • 2016-03-07
      • 1970-01-01
      • 2017-08-28
      • 2020-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多