31

Consider this appsettings.json:

{
  "Parent": {
    "ChildOne": "C1 from secrets.json",
    "ChildTwo": "C2 from secrets.json"
  }
}

According to Microsoft (https://blogs.msdn.microsoft.com/waws/2018/06/12/asp-net-core-settings-for-azure-app-service/), if an app using this config was deployed to an AppService in Azure, the config could be overwritten by creating Application settings in Azure in the style Parent:ChildOne / Parent:ChildTwo. To be clear: using colons to target a specific piece of config.

This works just fine with a standard AppService:

Colons are fine on an Azure App Service

However, if you're using Web App for Containers / i.e. a Docker image deployed to an Azure App Service on Linux (https://learn.microsoft.com/en-us/azure/app-service/containers/app-service-linux-intro) you cannot use colons:

Colons are not fine on Azure App Service for Linux

Why?

When you hover over the error you see this message: This field can only contain letters, numbers (0-9), periods ("."), and underscores ("_"). Using . does not work alas.

How do you configure say Parent:ChildOne in Azure? Parent.ChildOne does not work. Can anyone advise? I can't find any docs on this....

John Reilly
  • 5,791
  • 5
  • 38
  • 63

1 Answers1

67

After more experimentation than I'd like to admit I think I have the answer.

Where you use : on an App Service, use a __ (double underscore) on an App Service with containers.

So Parent__ChildOne instead of Parent:ChildOne.

To read a little more (not much more), I wrote this up as a blog post here: https://blog.johnnyreilly.com/2018/07/28/azure-app-service-web-app-containers-asp-net-nested-configuration/

John Reilly
  • 5,791
  • 5
  • 38
  • 63
  • 8
    Great, this helped! I'd like to add that for us the Linux part was important. Deploying the same dotnet core (3.1 LTS) API to a Windows App Service Plan can use `Parent:ChildOne` (the portal allows this), but on a Linux App Service Plan it has to be `Parent__ChildOne`. – Juliën Mar 25 '20 at 12:49
  • how to use special characters for example Test&Test – Niranjan Godbole Hosmar Feb 24 '21 at 13:10
  • @NiranjanGodboleHosmar I don't think you can. I think the best bet would be to go with standard naming conventions for that (i.e. `TestAndTest`). – BrainSlugs83 May 21 '21 at 23:35
  • How to use `-`? Does it become `_`? – imgen Oct 19 '21 at 04:19
  • Spent some sweet time on Friday evening to find out that, the bicep is able to update settings with : strangely. But failing to do manual or using Powershell scripts. I am using Bicep to add initial settings and then using PowerShell to update one of the value. – Kiru May 20 '22 at 18:03