在Azure Web应用程序设置中使用数组 [英] Using an array in Azure web app settings

查看:124
本文介绍了在Azure Web应用程序设置中使用数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的ASP.NET 5(RC1)代码中,我有一个类似于以下内容的appsetting.json:

In my ASP.NET 5 (RC1) code I have an appsetting.json that looks something like this:

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

在我的开发机器(即localhost)上运行代码时使用这些值.如果要覆盖wep应用程序在Azure应用程序设置中的"SomeSettings",我将如何指定"PropB"数组?

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?

我要在其中存储信息的SomeSettings.cs类如下:

The SomeSettings.cs class that I want to store the information in looks like this:

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

问题是"PropB"-如何在Azure中将数组或列表指定为字符串-甚至可能吗?

The problem is "PropB" - how to I specify an array or List as a string in Azure - is this even possible?

在我的Startup类的构造函数中,我有:

In my Startup class's constructor I have:

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

在我的Startup类的Configure方法中,我有:

And in my Startup class's Configure methods I have:

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

推荐答案

像这样在应用程序设置"下添加设置将达到目的... 请注意下面的:0"和:1"

Adding the settings under "App settings" like this will do the trick... Notice the ":0" and ":1" below

格式:键->值

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

如果您不是在Windows上运行,请用双下划线__替换冒号:,以使您的应用查看设置.所以而不是例如SomeSettings:PropA,您将使用SomeSettings__PropA.

If you aren't running on Windows, replace the colon : with double underscore __ to get your app to see the settings. So instead of e.g. SomeSettings:PropA, you'd use SomeSettings__PropA.

这篇关于在Azure Web应用程序设置中使用数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆