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:
- Open the Azure Portal at https://portal.azure.com
- Navigate to your Azure App Service Web App.
- Under Settings open up the Configuration option
- The Application settings section can be used to manage the settings for the application.
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
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
Here are 2 examples of accessing the Application Settings from Java:
String value1 = System.getenv("MySettingOne"); String value2 = System.getenv("APPSETTING_MySettingOne");
Are these always KEY VALUE pair?
Can we specify any setting which is json (as example) and not a Key Value. If so, can you share an example ?
Web App Application Settings are key/value pairs of type String so you could put any string/text value in them.
Do you know how Azure can overwrite the app settings under the hood without changing web.config? I am trying to do the same for my testing environment and in automated tools.
When you set the App Settings within the Azure Portal for an Azure Web App, those settings will automatically override anything that is in the web.config file that’s deployed.
If you have a lot of apps with a lot of the same settings. https://azure.microsoft.com/en-us/services/app-configuration/
How can I overwrite React .env variables using application settings.