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

查看:11
本文介绍了在 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"
        ]
    }
}

在我的开发机器(即本地主机)上运行代码时使用这些值.如果我想为 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天全站免登陆