Search Support

Configure App Service Settings

Learn how to manage and customize the configuration settings for your Azure App Service.

Configuring Application Settings and Connection Strings

Last updated: July 20, 2023

Azure App Service allows you to configure various application settings and connection strings that are crucial for your application's runtime behavior. These settings are injected as environment variables into your application's process, making them accessible without hardcoding sensitive information directly into your code.

Application Settings

Application settings are key-value pairs that control aspects of your application's configuration. They are often used for:

You can manage application settings through the Azure portal, Azure CLI, or PowerShell.

Using the Azure Portal

  1. Navigate to your App Service instance in the Azure portal.
  2. In the left-hand menu, under Settings, select Configuration.
  3. Go to the Application settings tab.
  4. Click New application setting.
  5. Enter the Name (the environment variable name) and Value for your setting.
  6. Click OK and then Save at the top of the blade.
# Example: Accessing an application setting in C#
string apiKey = Environment.GetEnvironmentVariable("MY_API_KEY");

# Example: Accessing an application setting in Node.js
const logLevel = process.env.LOG_LEVEL || 'info';

Connection Strings

Connection strings are used to establish connections to external data sources, such as Azure SQL Database, Cosmos DB, or other databases. App Service provides a dedicated section for managing these.

When you define a connection string, App Service automatically creates two environment variables:

It's recommended to use the named variable (e.g., SQLAZURECONNSTR_MyDatabase) as it follows a standard convention.

Using the Azure Portal for Connection Strings

  1. Navigate to your App Service instance in the Azure portal.
  2. In the left-hand menu, under Settings, select Configuration.
  3. Go to the Connection strings tab.
  4. Click New connection string.
  5. Select the Name (e.g., MyDatabase) and the Type of database.
  6. Provide the connection string details. The portal often pre-fills these for you if you select an Azure service.
  7. Click OK and then Save.
# Example: Accessing a connection string in C#
string connectionString = Environment.GetEnvironmentVariable("SQLAZURECONNSTR_MyDatabase");
// Use connectionString to configure your DbContext or database client

Important Note on Secrets Management

For enhanced security, consider using Azure Key Vault to store and manage your secrets, including connection strings and API keys. You can then reference Key Vault secrets directly within your App Service's application settings.

Deployment Slots

Configuration settings (both application settings and connection strings) can be configured independently for different deployment slots (e.g., staging, production). This allows you to test settings in a staging environment before swapping to production.

When you swap slots, you have the option to "swap application configuration settings". If you choose this, settings marked with a "Deployment slot setting" toggle set to "On" in the portal will be swapped along with the code. If it's "Off", the setting will remain with the slot it was originally configured for.

Best Practices