Search code examples
azureweb-configenvironment-variablesazure-web-app-service

How to override web.config values in custom section in Azure Web App?


It is possible in Azure Web App to override web.config AppSettings section easily. E.g. if I have the following web.config:

<appSettings>   
    <add key="AllowedCORSOrigin" value="http://localhost:26674"/>
</appSettings>

I can override it in the app settings UI in the portal like that:

enter image description here

I have also a custom section in the web.config:

<AdWordsApi>
    <add key="OAuth2RefreshToken" value="TOKEN" />
</AdWordsApi>

Is it possible to override it somehow as well? I have tried AdWordsApi.OAuth2RefreshToken and AdWordsApi:OAuth2RefreshToken, but that does not work that easily.

P.S. It's interesting to know if it's possible with other custom sections like e.g if I want another authentication mode on the server.

<system.web>
    <authentication mode="None" />
</system.web>

Solution

  • Short answer is that it is not possible.

    The mechanism you describes only works with App Settings and Connection Strings. High level, the way it works is:

    • Your Azure App Settings become environment variables
    • At runtime, a special module sets those dynamically in the .NET config system. Note that the physical web.config is never modified.

    But it would be hard to make such mechanism work on arbitrary config sections, as those could not be dynamically affected without modifying the physical file.