Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>(); 
like image 917
Kenneth Kryger Sørensen Avatar asked Dec 03 '15 10:12

Kenneth Kryger Sørensen


People also ask

How do I change the connection string in Azure App Service?

Configure connection strings. In the Azure portal, search for and select App Services, and then select your app. In the app's left menu, select Configuration > Application settings. For ASP.NET and ASP.NET Core developers, setting connection strings in App Service are like setting them in <connectionStrings> in Web.

How do I edit Azure Web config?

If you want to change web. config files you can use the Azure portal, there is a tool called "App Service Editor" in preview or Kudu that lets you edit any of the files you've deployed.

How do I set an environment variable in Azure portal?

To set environment variables when you start a container in the Azure portal, specify them in the Advanced page when you create the container. Under Environment variables, enter NumWords with a value of 5 for the first variable, and enter MinLength with a value of 8 for the second variable.


1 Answers

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.

like image 159
Kenneth Kryger Sørensen Avatar answered Sep 19 '22 03:09

Kenneth Kryger Sørensen