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

筅森魡賤 提交于 2019-12-24 05:46:28

问题


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:

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>

回答1:


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:


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.




回答3:


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



来源:https://stackoverflow.com/questions/40300716/how-to-override-web-config-values-in-custom-section-in-azure-web-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!