How to read Azure web site app settings values

ABB picture ABB · Jun 14, 2017 · Viewed 15.4k times · Source

I am trying to configure some key/value pairs for my Azure web application using app settings section on Windows Azure preview portal.

enter image description here

Now I am trying to read values like below

ConfigurationManager.AppSettings["MyWebApp.DbConnectionString"];

but it returns null values.

Reading app settings from Web.config in my web application works fine.

Answer

ABB picture ABB · Jun 14, 2017

I found the solution.

Keep values in web.config as well as in Azure App setting. When you are running/debugging application on your local environment it picks values from web.config.

When you deploy application on Azure it picks values from App setting.

//Below code work for both.
ConfigurationManager.AppSettings["KeyName"]

Keep key name same in web.config as well as in Azure app setting.