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

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.
    

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">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: <a target="_self" rel="noopener noreferrer nofollow" href="https://kristiadhy.hashnode.dev/how-to-secure-your-net-application-secrets-with-azure-key-vault-free-code-repository-included" style="pointer-events: none">Azure Key Vault: Secure .NET App Secrets</a></div>
</div>

## 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"`
        

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754867332649/e5450937-bb9b-4408-8e78-66f2e6e466b1.png align="left")

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Azure App Configuration supports <strong>hierarchical keys</strong> (use<code>:</code> as a separator), allowing you to mirror your application’s configuration structure.</div>
</div>

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

**Note: You can categorize your key using a label.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754867276460/46f8803e-66c7-4e1f-b802-a367657f725a.png align="left")

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

```json
{
  "AppSettings": {
    "AppName": "MyApp",
    "Developer": "Kristiadhy"
  }
}
```

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Never store secrets in <strong>Azure App Configuration</strong>. Store them in <strong>Azure Key Vault </strong>instead. You can still connect it to Azure App Configuration using a Key Vault reference. I'll explain this further in another article.</div>
</div>

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:

```csharp
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.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754874032442/45685d2f-ff54-4625-9003-04dd1b8f8ae6.jpeg align="left")

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Store this connection string in a secure location, such as <strong>user secrets</strong> for local development and environment variables in production.</div>
</div>

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.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1754880841083/dc6510a9-6207-4985-b953-647ef23330ca.png align="center")

**Update** `Program.cs` **to use Azure App Configuration**

Modify your `Program.cs` to load configuration from Azure:

```json
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();
```

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">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 <strong>multiple settings</strong> and <strong>an explanation </strong>in the <strong>free repository</strong> at the end of the article. ✅</div>
</div>

**Using the configuration in your code.**

```csharp
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](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.
