We've recently created a web app and uploaded it to Azure App Service. We also took a look at multiple ways to examine those files through the Azure portal interface and how we'd add extensions and deployment slots for our web app. We also took a look at a feature called Testing in Production and how to use PowerShell to automatically distribute the load between your Production and deployment slot. We wrapped up by looking at the Azure Resource Explorer to explore REST APIs and how to perform load testing. In this post, we'll take advantage of App Settings to store a Key/Value pair securely in Azure and access it in your web app.

Working with App Settings and Azure App Services

App Settings are used to store configurable items without making any changes to the code. The key-value pairs are stored behind the scenes in a configuration store which is nice because sensitive information never shows up in a web.config, etc. file. In order to take advantage of this, you'll need to log into your Azure account and go to your App Service that you created and look under Development Tools then you will see Application Settings. Open it and scroll down and you'll see App Settings as shown below.

We're going to add an App Setting in Azure. I added one with the key of Environment and the value is set to Staging

Open or create your ASP.NET MVC app and modify the appSettings section of the web.config file to add our Environment key/value pair as shown below :

    <add key="webpages:Version" value="" />
    <add key="webpages:Enabled" value="false" />
    <add key="Environment" value="Production" />

Now it is in our web configuration of our app. In order to see the value, we'll need to add it to a page to display the value.

If you're using ASP.NET MVC, then navigate to your appname/Views/Home/Index.cshtml file and add the following using statement followed by a call to ConfigurationManager as shown below :

@using System.Configuration
    ViewBag.Title = "Home Page";

<div class="jumbotron')">
    <h1>Testing App Settings</h1>


If you run the application locally, then you'll see Production as it is coming from the web.config file, but if you run it inside of Azure, then you'll see Staging as it is coming from the App Settings configuration store located in Azure. Neat stuff!