How to Integrate Azure App Configuration in ASP.NET Core for Centralized Settings

KristiadhyKristiadhy
5 min read

In an ASP .NET Core application, configuration values are often stored in appsettings.json.
For different environments, we typically create separate files such as appsettings.Development.json, appsettings.Staging.json, and appsettings.Production.json.

While this approach works, it comes with several drawbacks—especially in production:

  • Deployment Complexity.

    Even small configuration changes may require a full CI/CD pipeline run or manual updates in each environment on your cloud server. This slows down delivery and increases operational overhead.

  • Difficult to Maintain.

    If you have multiple environments (e.g., Development, Staging, and Production), keeping all configuration files synchronized can be error-prone. Missing or outdated values in one environment can lead to bugs or inconsistencies.

  • Limited Access Control.

    appsettings.json is accessible to anyone with file system access. Fine-grained access control—such as granting read-only permissions to specific keys—is not straightforward.

This is why you need central configuration.

A centralized configuration system solves these problems by providing:

  • One source of truth for configuration values.

  • Instant updates without requiring application redeployments.

  • Better security and access control for sensitive values.

💡
In the previous article, I explained how to connect your ASP .NET Core application to Azure Key Vault to store secrets. You can read it here: Azure Key Vault: Secure .NET App Secrets

Azure App Configuration

Azure App Configuration is a fully managed service that lets you store, manage, and distribute application settings from a single location.
Rather than storing configuration values in local files and including them in your codebase, you should keep them in a centralized store and retrieve them at runtime.

Key benefits:

  • Instant configuration updates without redeploying your app

  • Consistency across multiple environments and applications

  • Dynamic settings support, including feature flags

Let’s get started.

Setting Up Azure App Configuration.

  1. Create the service.
    In the Azure Portal, search for App Configuration in the top search bar.
    Click Create and provide the required details (subscription, resource group, region, and name). Once done, click Review + Create, then Create.

  2. Add configuration values.
    After the resource is created, open it and navigate to Configuration Explorer from the left-hand menu.
    Click + Create to add a new key-value pair.

  3. Define your settings.
    You can add keys in the same way you would structure them in appsettings.json. For example:

    • AppSettings:AppName"My Web App"

💡
Azure App Configuration supports hierarchical keys (use: as a separator), allowing you to mirror your application’s configuration structure.

The example below shows what it looks like in the Azure configuration.

Note: You can categorize your key using a label.

It’s similar to this structure in your appsettings.json:

{
  "AppSettings": {
    "AppName": "MyApp",
    "Developer": "Kristiadhy"
  }
}
💡
Never store secrets in Azure App Configuration. Store them in Azure Key Vault instead. You can still connect it to Azure App Configuration using a Key Vault reference. I'll explain this further in another article.

Now, let's look at how you can read it from your app.

Connecting your ASP NET Core app to Azure App Configuration.

Here’s how you can connect your app to Azure App Configuration.

Install the required NuGet packages

From your project directory, run:

dotnet add package Microsoft.Azure.AppConfiguration.AspNetCore

Retrieve the connection string from Azure

In the Azure Portal, navigate to your App Configuration resource and:

  • Go to Access Settings in the left-hand menu.

  • Copy the Primary Connection String.

Note: You'll have Read-Write keys or Read-Only keys. Please select accordingly.

💡
Store this connection string in a secure location, such as user secrets for local development and environment variables in production.

Note: To use a user secret in Visual Studio, right-click your project and select Manage User Secret. Then, enter the value as shown in the example below.

Update Program.cs to use Azure App Configuration

Modify your Program.cs to load configuration from Azure:

using Azure.Identity;

var builder = WebApplication.CreateBuilder(args);

// Connect to Azure App Configuration
builder.Configuration.AddAzureAppConfiguration(options =>
{
    options.Connect(builder.Configuration["AzureAppConfiguration:ConnectionString"]);
});

builder.Services.AddAzureAppConfiguration();

var app = builder.Build();

app.UseAzureAppConfiguration();

app.MapControllers();
app.Run();
💡
The above example is not recommended for connecting to your Azure App Configuration because the value will not automatically refresh if there is an update to the value. 🚫 I’ll provide a more robust approach with multiple settings and an explanation in the free repository at the end of the article. ✅

Using the configuration in your code.

public class AppConfigController : ControllerBase
{
  private readonly IConfiguration _configuration;

  public AppConfigController(IConfiguration configuration)
  {
    _configuration = configuration;
  }

  [HttpGet("Configuration")]
  public IActionResult GetAppConfigValueFromConfiguration()
  {
    var appSettings = new AppSettings
    {
      AppName = _configuration["AppSettings:AppName"]!,
      Developer = _configuration["AppSettings:Developer"]!
    };
    return Ok(appSettings);
  }
}

The example above is also not recommended 🚫; it’s better to use the Option Pattern instead of injecting the configuration directly into your controller. In the free repository below, I have provided a more robust approach ✅:

  • Using an extension method that makes your program.cs cleaner.

  • Different refresh settings with explanations to help you understand the refresh with multiple approaches.

  • Using the Option Pattern for a more effective approach.

Grab this for repository free: https://github.com/kristiadhy/AzureAppConfigAndKeyVaultIntegration

Note: If you find this helpful, please like the repo.

Conclusion

By using Azure App Configuration, you centralize configuration management, enabling instant updates across environments without redeployments.

This combination delivers:

  • Centralized management for all application settings.

  • Consistent configuration across multiple apps and environments.

  • Faster, safer updates without downtime.

In the next article, I'll explain how to integrate the Azure App Configuration and Key Vault.

0
Subscribe to my newsletter

Read articles from Kristiadhy directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Kristiadhy
Kristiadhy

Experienced Full Stack .NET developer with a proven track record of designing and implementing robust business applications. Proficient in using ASP.NET Core Web API, Blazor, and WinForms to deliver high-quality, efficient code and scalable solutions. Strong focus on implementing industry best practices for cleaner and scalable outcomes.