Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
224 views
in Technique[技术] by (71.8m points)

c# - 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:

{
    "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?

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; }
}

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

In my Startup class's constructor I have:

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

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

var someSettings = configuration.GetSection("SomeSettings").Get<SomeSettings>();
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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. So instead of e.g. SomeSettings:PropA, you'd use SomeSettings__PropA.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...