Override applicationSettings "MySite.Properties.Settings.MySetting" in Azure Website Override applicationSettings "MySite.Properties.Settings.MySetting" in Azure Website azure azure

Override applicationSettings "MySite.Properties.Settings.MySetting" in Azure Website


Have you added the applicationSettings to the section group?

<configSections>    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >        <section name="Tools.Instrumentation.Properties.Settings"                  type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"                  requirePermission="false" />    </sectionGroup></configSections>


One alternative is to set the App Settings from the Azure Portal. Go to the Azure Portal->Navigate to your website->Settings->App Settings and set the key, value pair there.

All settings will show up as environment variables, so you can set different values for the same settings in your test and production environments.

See here for more info:

http://azure.microsoft.com/blog/2013/07/17/windows-azure-web-sites-how-application-strings-and-connection-strings-work/


I asked around Microsoft's support & could not get an answer for this issue as I wanted to do this too. Fortunately while trying to better understand Microsoft's Web Deploy I discovered how to do this.

First, you'll need to use an external config file instead of just adding them into the web.config file. In your web.config file replace the following:

<applicationSettings>    <MySite.Web.Properties.Settings>        <setting name="MySetting" serializeAs="String">            <value>coolValue</value>        </setting>    </MySite.Web.Properties.Settings></applicationSettings>

Use an external configuration file like this instead:

<applicationSettings>    <MySite.Web.Properties.Settings configSource="BusinessLogic.config" /></applicationSettings>

Also in your web.config file you will need to add the following to your configSections:

<configSections>    <sectionGroup name="applicationSettings">        <section name="MySite.Web.Properties.Settings" />    </sectionGroup></configSections>

You can read the MSDN article for more on this if need be.

In your BusinessLogic.config file, located in your root with your web.config file you would add your settings:

<MySite.Web.Properties.Settings>    <setting name="SecretPassword" serializeAs="String">        <value>1234567890abc!@#</value>    </setting></MyApplication.Properties.Settings>

Now manually add this same BusinessLogic.config file to your site on Azure with the settings you want it to have in Azure.

Finally open up your .csproj file and look for the following XML configuration:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">

Within there you can exclude files from deployment by adding a line like this:

<ExcludeFilesFromDeployment>BusinessLogic.config</ExcludeFilesFromDeployment>

If you need to exclude more files, you can separate them with a semicolon.

Now in my case when I commit all these files to my git repository, Azure will automatically grab them & put them in a temporary file where it will build the project and then deploy it to the folder where the website lives. Upon deploying it will notice to ignore the BusinessLogic.config file and the file you manually placed in Azure will be used instead.