Override applicationSettings "MySite.Properties.Settings.MySetting" on the Azure Website

I have a website (not a web role) that I am deploying to Azure using the base layer. The file web.config

has the following automatically generated website settings section:

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

      

I am trying to override a value MySetting

in an Azure section Web Apps -> MySite -> Configure -> app settings

. The idea is that a live site has a different meaning than a development version. I try to avoid storing the live website value in the web.config file (and doesn't do any conversions).

I have tried the following values ​​in the app settings

azure web application config section:

  • MySetting

    = somethingElse

  • MySite.Web.Properties.Settings.MySetting

    = somethingElse

None of these things worked. I like the new strongly typed settings class in .NET and don't really need to align the application settings (using the old way).

Does anyone know how to override these types of settings in Azure?

+3


source to share


3 answers


Have you added the app settings 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>

      

0


source


One option is to install app preferences from the Azure Portal. Go to Azure portal-> Go to your site-> Settings-> App Settings and set the key pair, value there.

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



See here for more details:

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

0


source


I asked about Microsoft support and couldn't get an answer to this question as I wanted to do that too. Luckily, while trying to understand Microsoft Web Deploy better, I discovered how to do this.

You need to use an external config file first, not just add them to your 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 config file instead:

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

      

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

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

      

You can read the MSDN article to find out about this if needed.

In your BusinessLogic.config file, located in the root directory of your web.config file, you 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 them to be in Azure.

Finally, open the .csproj file and find the following XML configuration:

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

      

Internally, you can exclude files from deployment by adding the following line:

<ExcludeFilesFromDeployment>BusinessLogic.config</ExcludeFilesFromDeployment>

      

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

Now when I upload all of these files to my git repository, Azure will automatically grab them and put them in a temporary file where it will build the project and then deploy it to the folder where the site lives. When deployed, it will ignore the BusinessLogic.config file and will instead use the file you manually placed in Azure.

0


source







All Articles