All web applications have some kind of configurations that are set on the server. The method of storing and accessing these settings varies on different web application platforms. In ASP.NET they are normally stored within <appSettings> element of the web.config file. Web Apps hosted in Microsoft Azure App Service allows for these settings to be configured in the cloud, and then subsequently accessed from application code as needed. With .NET applications the application settings are accessed the same as AppSettings contained within the web.config file. In other web platforms (Java, Node.js, PHP and Python) the application settings can be accessed using Environment Variables.

Application Settings are stored as a Key / Value pairs. These values are stored as strings. The Key is a string that is used as a dictionary style lookup to retrieve the value that is also saved as a string value.

Configure Application Settings using Azure Portal

Managing Application Settings for an Azure App Service Web App can be performed using the Azure Portal. This provides an easy to use, graphical interface for configuring the Application Settings for an application hosting in Azure App Service.

Here are the necessary steps to locate and access the App Settings for an Azure Web App:

  1. Open the Azure Portal at https://portal.azure.com
  2. Navigate to your Azure App Service Web App.
  3. Under Settings open up the Configuration option
  4. The Application settings section can be used to manage the settings for the application.
Azure Web App: Application Settings 1
Screenshot: App Service Configuration pane

Configure Application Settings using Azure CLI

There are times when command-line scripts or automation is needed to configure a Web App hosted in Azure App Service. The Application Settings on the App Service App can be configured from the Azure CLI using the az webapp config appsettings set command.

az webapp config appsettings set `
  --name <web-app> --resource-group <resource-group> `
  --settings <settings>

This command accepts at minimum the parameters shown in the above example. These required parameters are defined as follows:

  • --name: This specifies the name of the App Service Web App to configure.
  • --resource-group: This specifies the Resource Group where the App Service Web App is organized within.
  • --settings: This specifies a space-separated list of app settings Key / Value pairs. Alternatively, @(file) can be used to load from a file instead.

Here’s an example usage of this command that sets two application setting values on a web app:

az webapp config appsettings set `
  --name build5nines-app --resource-group build5nines`
  --settings "Key1=Value1" "Key2=Value2"

If you need to target a Deployment Slot to configure the application settings, then you can do so using the following two parameters on this command:

  • --slot: This specifies the Deployment Slot name. If not specified, the Production slot is used.
  • --slot-settings: This specifies the space-separated list of app settings Key / Value pairs to set for the Deployment Slot specified. This also supports the use of @(file) to load from a file alternatively.

Access Application Settings from .NET Framework

Accessing the Application Settings from a .NET Framework application (such as ASP.NET and ASP.NET MVC) is performed using the ConfigurationManager class.

Here’s an example of accessing an Application Setting from C#:

using System.Configuration;

string value = ConfigurationManager.AppSettings["key"];

Access Application Settings from Node.js

Azure Web App application settings are exposed to Node.js javascript code as Environment Variables. These Environment Variables have the same name as the Application Settings key. Additionally, they can be accessed using the APPSETTING_ prefix.

Here are 2 examples of accessing the Application Settings from Javascript running on Node.js:

var value1 = process.env.MySettingOne;
var value2 = process.env.APPSETTING_MySettingOne;

Access Application Settings from Java

Azure Web Application settings are exposed to Java code through Environment Variables. These Environment Variables have the same name as the Application Setting key. Additionally, they can be accessed using the APPSETTINGS_ prefix.

Here are 2 examples of accessing the Application Settings from Java:

String value1 = System.getenv("MySettingOne");
String value2 = System.getenv("APPSETTING_MySettingOne");

Happy coding!

Microsoft MVP

Chris Pietschmann is a Microsoft MVP, HashiCorp Ambassador, and Microsoft Certified Trainer (MCT) with 20+ years of experience designing and building Cloud & Enterprise systems. He has worked with companies of all sizes from startups to large enterprises. He has a passion for technology and sharing what he learns with others to help enable them to learn faster and be more productive.
HashiCorp Ambassador Microsoft Certified Trainer (MCT) Microsoft Certified: Azure Solutions Architect