Using App Settings in Azure Web Apps

Friday, 09 October 2015

How to use app settings in Azure web apps

#asp.net#azure-app-service

This article was published at GitHub. It is open source and you can make edits, comments etc.

I'm on a hackathon today where we are looking at retrofitting some DevOps principles to an existing ASP.net 4.5 web application.

I learnt something about app settings which I did not know so thought I'd share it.

Settings in ASP.net

In ASP.net, the easiest way to store application settings is in the Web.Config file under the appSettings section. This is a key/value pair and is great for storing things like API urls, settings and other things that affect your app's behaviour.

In you code, you can easily access the settings from Web.Config via ConfigurationManager.AppSettings.

ConfigurationManager.AppSettings["keyname"];

Settings in Azure Web App

If you host your website in an Azure Web App, there is a really neat feature that that lets you add settings at the web app level which overwrite the settings from Web.Config at runtime. You configure these in the 'application settings' menu for your web app in the Azure portal.

If a setting is absent in Azure, then the application will default back to what is in the Web.Config.

This allow you to do really useful things like use a local API for dev/test but use a production API in production without changing your code.

Hope that helps someone

Got a comment?

All my articles are written and managed as Markdown files on GitHub.

Please add an issue or submit a pull request if something is not right on this article or you have a comment.

If you'd like to simply say "thanks", then please send me a .

An error has occurred. This application may no longer respond until reloaded. Reload 🗙