Migrate webconfig’s appsettings to Azure Service Configuration

If you are currently migrating your application to Azure environment using WebRole, you might need to move your appsettings in Web configuration (web.config) to Azure Service configuration (.cscfg file). By using this approach, you may change your configurations directly from Azure Portal.

So, here are the steps:

  1. Add settings from WebRole properties based on your appsettings section in your webconfig AzureConfig1AzureConfig2
  2. Change your code from ConfigurationManager.AppSettings[“configs”]; to CloudConfigurationManager.GetSetting(“configs”);AzureConfig3

And we’re done… and here are the rules of thumb:

  1. If the application runs on Azure environment (Local Simulator and Cloud), it will look for the settings in .cscfg file first, if the setting couldn’t be found in .cscfg file, it will search in web.config, and if web.config doesn’t contain the desired setting, it will return null.
  2. If the application runs on Local environment, it will look for the settings in web.config only, if the settings couldn’t be found, it will return null.

Leave a Reply

Your email address will not be published. Required fields are marked *