In Azure App Configuration I have named my settings as so: "Section1__SubSection1__MySetting". When trying to bind configuration to my corresponding Options class in my .NET 6 application, it fails to map correctly (null). If I change the "__" to ":" it works fine.
I'm trying to untangle why/how you can use double underscore to denote nesting, because it is generally recommended to use "__" for more universal support. If I use ":" in my Azure App Configuration keys, would it still work if I run my app on a Linux machine?
Can someone please explain all this?
Written with [StackEdit](>Double underscore not equivalent to colon when trying to denote nesting
Yes, denoting nested configuration varies depending on the Hosting Environment (Windows/Linux).
If you want to set the nested configuration in Windows App, then you need to mention the :
symbol following the nested key name (which you have already tried).
You can see that same is mentioned in the MSDoc
In a default Linux app service or a custom Linux container, any nested JSON key structure in the app setting name like
ApplicationInsights:InstrumentationKey
needs to be configured in App Service asApplicationInsights__InstrumentationKey
for the key name. In other words, any:
should be replaced by__
(double underscore).
__
double underscore.Check the below workaround:
I have followed the Azure App Configuration with ASP.NET Core to add the Nested Configuration.
I have created a Web App and deployed to Linux App Service
.
Initially I have set the Configuration with :
and __
and tried to retrieve the values.
In Program.cs
:
string myconn = builder.Configuration.GetConnectionString("AppConfig");
//string myconn = builder.Configuration.GetSection("AppConfig").Value;
builder.Configuration.AddAzureAppConfiguration(myconn);
In Index.cshtml
:
<h4>With Semicolon - @myconfig["Test:Settings:SemiColon"]</h4>
<h4>With UnderScore - @myconfig["Test__Settings__UnderScore"]</h4>
Local Output:
I have deployed the App to Azure Linux App service
.
Deployed App Output:
Both :
and __
worked for me for the deployed app in Linux App Environment
with Azure App Configuration
.
When I tried same with Azure App Settings
,
Local appsettings.json
file:
"Section1": {
"SubSection1": {
"MySetting": "Value from Local"
}
}
:
and tried to retrieve the value.Local Output:
:
worked here.
I have deployed the App to Azure Linux App service
.
To override the value with the Azure App Settings, I have set the value as below (with:
).
__
and it allowed me to add.Deployed App Output:
If I use ":" in my Azure App Configuration keys, would it still work if I run my app on a Linux machine?
Yes, :
works on Azure Linux App Service
in Azure App Configuration
.
Whereas only __
worked on Azure Linux
with Azure App Settings
.