Back to top

Defining JSON-structured config in Azure App Service configuration

We’ve just gone live with our new infrastructure on Azure, which (temporarily) will use YARP to proxy all requests in our .NET Core web app to our old .NET Framework app, where they haven’t yet been ported across to the Core app.

I say “temporarily” because of course the plan is to now start migrating all the rest of our actions from the old .NET Framework project to the .NET Core project. We’ve done a handful of them already, and now that we’ve gone live with those, and proved that it all works well, we can start doing the rest!

We use App Service Slots to for each of our testing environments, and I usually control the values of a lot of configuration settings via the Azure App Service Configuration, so that we can edit them easily on-the-fly if needed.

One struggle I had with this was finding documentation to clearly explain how to define configuration in the App service Configuration for the YARP cluster fallback address, which is defined usually in the AppSettings.json file - ie., it’s JSON.

I did read in a few places that we should be able to define JSON directly in the App Service Configuration, but I couldn’t get it to work, it always complained of syntax errors.

In the AppSettings.json file, the structure of this particular config item looks something like this:

  "ReverseProxy": {
    "Routes": {
      "fallbackRoute": {
        "ClusterId": "fallbackClusterMainPlatform",
        "Order": "1000",
        "Match": {
          "Hosts": [
            "*"
          ],
          "Path": "{**catch-all}"
        },
        "Transforms": [
          {
            "X-Forwarded": "Set"
          }
        ]
      }
    },
    "Clusters": {
      "fallbackClusterMainPlatform": {
        "Destinations": {
          "fallbackApp": {
            "Address": "<FRAMEWORK SITE URL>"
          }
        }
      }
    }
  },

In order to define a configuration that overrides this at the App Service level in the portal (e.g. for different environments/slots), you can use underscores to break up the “levels” within the JSON. In the case of this specific config item, it should look like this:

ReverseProxy__Clusters__fallbackClusterMainPlatform__Destinations__fallbackApp__Address

In the App Service Configuration, it looks like this in the advanced editor:

{
    "name": "XDT_MicrosoftApplicationInsights_Mode",
    "value": "Recommended",
    "slotSetting": true
}

If this helped you, let me know!