简体   繁体   English

在 Azure web 应用程序设置中使用数组

[英]Using an array in Azure web app settings

In my ASP.NET 5 (RC1) code I have an appsetting.json that looks something like this:在我的 ASP.NET 5 (RC1) 代码中,我有一个 appsetting.json 看起来像这样:

{
    "SomeSettings": {
        "PropA": "ValueA",
        "PropB": [
            "ValueB1",
            "ValueB2"
        ]
    }
}

These value are used when a run the code on my dev machine (ie. localhost).在我的开发机器(即本地主机)上运行代码时使用这些值。 If I want to overwrite the "SomeSettings" in Azure's Application settings for the wep app, how would I specify the "PropB" array?如果我想为 wep 应用程序覆盖 Azure 应用程序设置中的“SomeSettings”,我将如何指定“PropB”数组?

The SomeSettings.cs class that I want to store the information in looks like this:我要在其中存储信息的 SomeSettings.cs class 如下所示:

public class SomeSettings
{
    public string PropA { get; set; }
    public List<string> PropB { get; set; }
}

The problem is "PropB" - how to I specify an array or List as a string in Azure - is this even possible?问题是“PropB”——如何在 Azure 中将数组或列表指定为字符串——这甚至可能吗?

In my Startup class's constructor I have:在我的 Startup 类的构造函数中,我有:

var builder = new ConfigurationBuilder()
    .AddJsonFile("appsettings.json")
    .AddEnvironmentVariables();

And in my Startup class's Configure methods I have:在我的 Startup 类的 Configure 方法中,我有:

var someSettings = configuration.GetSection("SomeSettings").Get<SomeSettings>();

Adding the settings under "App settings" like this will do the trick... Notice the ":0" and ":1" below像这样在“应用设置”下添加设置就可以了……注意下面的“:0”和“:1”

Format: Key -> Value格式:键 -> 值

SomeSettings:PropA -> AzureValueA
SomeSettings:PropB:0 -> AzureValueB1
SomeSettings:PropB:1 -> AzureValueB2

If you aren't running on Windows, replace the colon : with double underscore __ to get your app to see the settings.如果您不是在 Windows 上运行,请将冒号:替换为双下划线__以使您的应用程序查看设置。 So instead of eg SomeSettings:PropA , you'd use SomeSettings__PropA .所以,而不是例如SomeSettings:PropA ,你会使用SomeSettings__PropA

In case the array value is an object (see that WriteTo value below) you can copy the entire WriteTo value, update the values if you need to and create an application setting for it as follows;如果数组值为 object(请参阅下面的 WriteTo 值),您可以复制整个 WriteTo 值,如果需要更新值并为其创建应用程序设置,如下所示;

  "Serilog": {
    "WriteTo": [
      {
        "Name": "ApplicationInsights",
        "Args": {
          "restrictedToMinimumLevel": "Information",
          "telemetryConverter": "Serilog.Sinks.ApplicationInsights.Sinks.ApplicationInsights.TelemetryConverters.TraceTelemetryConverter, Serilog.Sinks.ApplicationInsights",
          "instrumentationKey": "YOUR-KEY"
        }
      },
      {
        "Name": "UmbracoFile",
        "Args": {
          "RestrictedToMinimumLevel": "Error"
        }
      },
      {
        "Name": "Async",
        "Args": {
          "configure": [
            {
              "Name": "Console"
            }
          ]
        }
      }

    ]
  }

在此处输入图像描述

Simple approach is store the JSON as string in AppSetting, and de-serialize by yourself简单的方法是将 JSON 作为字符串存储在 AppSetting 中,并自行反序列化

var serializer = new JavaScriptSerializer();
var settings = serializer.Deserialize<SomeSettings>(configuration.GetSection("SomeSettings"));

or you will have to create your own customer configuration i believe.或者我相信您将不得不创建自己的客户配置。 https://msdn.microsoft.com/en-us/library/2tw134k3.aspx https://msdn.microsoft.com/en-us/library/2tw134k3.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure function 使用应用程序设置无法访问运行时 - Azure function runtime unreachable using app settings 如何将连接字符串存储在 Azure Vault 和 map 中返回到 Azure Web App 中的配置设置? - How to store connection string in Azure Vault and map it back to the configuration settings in Azure Web App? 如何在 Spring 启动时读取 Azure web 站点应用程序设置值 java class - How to read Azure web site app settings values in Spring boot java class 如何使用 Azure 管道在 Azure AD 中注册一个 web 应用程序? - How to register a web app in Azure AD using Azure Pipelines? 无法更新 Azure App 中的配置设置 - Unable to Update Configuration Settings in Azure App Azure web 应用程序出现 BadImageFormatException 错误 - BadImageFormatException error on Azure web app 在 Azure 应用程序服务上运行的 WCF 服务的 SSL 设置出现问题 - Problem with SSL settings for WCF service running on Azure app service 从 IntelliJ 部署 azure function 删除所有应用程序设置 - Deploying azure function from IntelliJ removes all app settings Azure PHP web 应用程序使用系统分配的托管身份连接到 Azure 存储 Blob - Azure PHP web app using system assigned managed identity connecting to Azure Storage Blob 一个 Azure Web App 可以只包含 azure web jobs - Can an Azure Web App consist exclusively of azure web jobs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM