3
votes

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>
4

4 Answers

5
votes

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.

2
votes

If you are using Visual Studio use web.config transformations to change configuration settings depending on whether you are running locally or deploying to Azure:

How to Transform Web.config

In simple terms you create one more more build configurations (typically Debug & Release). In your Visual Studio solution right-click on your existing web.config file and click "Add Config Transform", this will create a Web.Debug.Config and Web.Release.Config file which you can then customise with specific settings depending on the environment. Link this with your Azure build configuration and you can then have any combination of settings for local and remote deployment.

0
votes

This is old but leaving this reference to how to use Azure Resource Manager to potentially solve this.

0
votes

You can transform the values by the listed in VSTS by doing the following steps in App.Release.config:-

  1. Add xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" in configuration section
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    </configuration>
  1. Add xdt:Transform="Replace" in custom section like below
<AdWordsApi  xdt:Transform="Replace">
    <add key="OAuth2RefreshToken" value="TOKEN" />
</AdWordsApi>
  1. Create variable token in the release pipeline e.g OAuth2RefreshToken

  2. Then in file config use it as following

<AdWordsApi  xdt:Transform="Replace">
    <add key="OAuth2RefreshToken" value="#{OAuth2RefreshToken}#" />
</AdWordsApi>