C# 在Azure web app设置中使用阵列
在我的ASP.NET 5(RC1)代码中,我有一个appsetting.json,看起来像这样:C# 在Azure web app设置中使用阵列,c#,azure,asp.net-core,azure-web-app-service,C#,Azure,Asp.net Core,Azure Web App Service,在我的ASP.NET 5(RC1)代码中,我有一个appsetting.json,看起来像这样: { "SomeSettings": { "PropA": "ValueA", "PropB": [ "ValueB1", "ValueB2" ] } } public class SomeSettings { public string PropA { get; set; }
{
"SomeSettings": {
"PropA": "ValueA",
"PropB": [
"ValueB1",
"ValueB2"
]
}
}
public class SomeSettings
{
public string PropA { get; set; }
public List<string> PropB { get; set; }
}
在我的开发机器(即localhost)上运行代码时使用这些值。如果我想覆盖Azure的wep应用程序应用程序设置中的“SomeSettings”,我将如何指定“PropB”数组
我要在其中存储信息的SomeSettings.cs类如下所示:
{
"SomeSettings": {
"PropA": "ValueA",
"PropB": [
"ValueB1",
"ValueB2"
]
}
}
public class SomeSettings
{
public string PropA { get; set; }
public List<string> PropB { get; set; }
}
在我的Startup类的Configure方法中,我有:
var someSettings = configuration.GetSection("SomeSettings").Get<SomeSettings>();
var someSettings=configuration.GetSection(“someSettings”).Get();
像这样在“应用程序设置”下添加设置将达到效果。。。
请注意下面的“:0”和“:1”
格式:键->值
SomeSettings:PropA -> AzureValueA
SomeSettings:PropB:0 -> AzureValueB1
SomeSettings:PropB:1 -> AzureValueB2
如果您没有在Windows上运行,请将冒号
:
替换为双下划线\uuuu
,以使您的应用程序查看设置。因此,您可以使用SomeSettings\uuuu-PropA代替例如SomeSettings:PropA,简单的方法是将JSON作为字符串存储在AppSetting中,然后自己反序列化
var serializer = new JavaScriptSerializer();
var settings = serializer.Deserialize<SomeSettings>(configuration.GetSection("SomeSettings"));
var serializer=newJavaScriptSerializer();
var settings=serializer.Deserialize(configuration.GetSection(“SomeSettings”);
或者,我相信您必须创建自己的客户配置 到今天为止,它工作得很好。我只是想确认我们的方法还在这里。我们使用VST通过PS脚本部署WebApp参数,现在我们可以推送阵列。谢谢。您知道如何将SomeSettings\uuuu PropB
表示为空数组吗?这也适用于Azure函数的local.settings.json。如果您使用Azure函数,请不要忘记在设置名称中添加值
前缀。i、 e.value:SomeSettings:PropB:0