Skip to content

Commit 12a651a

Browse files
committed
Add Entra ID tab - draft commit
1 parent e917d3f commit 12a651a

File tree

1 file changed

+79
-7
lines changed

1 file changed

+79
-7
lines changed

articles/azure-app-configuration/quickstart-aspnet-core-app.md

Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
2-
title: Quickstart for Azure App Configuration with ASP.NET Core | Microsoft Docs
2+
title: Quickstart for Azure App Configuration with ASP.NET Core
33
description: Create an ASP.NET Core app with Azure App Configuration to centralize storage and management of application settings for an ASP.NET Core application.
44
services: azure-app-configuration
55
author: zhenlan
66
ms.service: azure-app-configuration
77
ms.devlang: csharp
88
ms.custom: devx-track-csharp, mode-other, engagement-fy23
99
ms.topic: quickstart
10-
ms.date: 02/20/2024
10+
ms.date: 11/20/2024
1111
ms.author: zhenlwa
1212
#Customer intent: As an ASP.NET Core developer, I want to learn how to manage all my app settings in one place.
1313
---
@@ -47,13 +47,43 @@ dotnet new webapp --output TestAppConfig --framework net6.0
4747

4848
## Connect to the App Configuration store
4949

50-
1. Navigate into the project's directory *TestAppConfig*, and run the following command to add a [Microsoft.Azure.AppConfiguration.AspNetCore](https://www.nuget.org/packages/Microsoft.Azure.AppConfiguration.AspNetCore) NuGet package reference:
50+
Connect to your App Configuration store using Microsoft Entra ID (recommended), or a connection string.
51+
52+
1. Navigate into the project's directory *TestAppConfig*, and run the following command to add NuGet package references.
53+
54+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
5155

5256
```dotnetcli
5357
dotnet add package Microsoft.Azure.AppConfiguration.AspNetCore
58+
dotnet add package Azure.Identity
59+
```
60+
61+
### [Connection string](#tab/connection-string)
62+
```dotnetcli
63+
dotnet add package Microsoft.Azure.AppConfiguration.AspNetCore
64+
```
65+
---
66+
67+
1. Run the following command to restore packages for your project:
68+
69+
```dotnetcli
70+
dotnet restore
5471
```
5572
56-
1. Run the following command. The command uses [Secret Manager](/aspnet/core/security/app-secrets) to store a secret named `ConnectionStrings:AppConfig`, which stores the connection string for your App Configuration store. Replace the `<your_connection_string>` placeholder with your App Configuration store's connection string. You can find the connection string under **Access Keys** of your App Configuration store in the Azure portal.
73+
1. Create a user secret for the application by navigating into the *TestAppConfig* folder and running the following command.
74+
75+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
76+
77+
The command uses [Secret Manager](/aspnet/core/security/app-secrets) to store a secret named `Endpoints:AppConfiguration`, which stores the endpoint for your App Configuration store. Replace the `<your-App-Configuration-endpoint>` placeholder with your App Configuration store's endpoint. You can find the endpoint in your App Configuration store's **Access settings** in the Azure portal.
78+
79+
```dotnetcli
80+
dotnet user-secrets init
81+
dotnet user-secrets set Endpoints:AppConfiguration "<your-App-Configuration-endpoint>"
82+
```
83+
84+
### [Connection string](#tab/connection-string)
85+
86+
The command uses [Secret Manager](/aspnet/core/security/app-secrets) to store a secret named `ConnectionStrings:AppConfig`, which stores the connection string for your App Configuration store. Replace the `<your_connection_string>` placeholder with your App Configuration store's connection string. You can find the connection string in your App Configuration store's **Access settings** in the Azure portal.
5787
5888
```dotnetcli
5989
dotnet user-secrets init
@@ -62,10 +92,52 @@ dotnet new webapp --output TestAppConfig --framework net6.0
6292
6393
> [!TIP]
6494
> Some shells will truncate the connection string unless it's enclosed in quotes. Ensure that the output of the `dotnet user-secrets list` command shows the entire connection string. If it doesn't, rerun the command, enclosing the connection string in quotes.
65-
95+
6696
Secret Manager stores the secret outside of your project tree, which helps prevent the accidental sharing of secrets within source code. It's used only to test the web app locally. When the app is deployed to Azure like [App Service](../app-service/overview.md), use the *Connection strings*, *Application settings* or environment variables to store the connection string. Alternatively, to avoid connection strings all together, you can [connect to App Configuration using managed identities](./howto-integrate-azure-managed-service-identity.md) or your other [Microsoft Entra identities](./concept-enable-rbac.md).
97+
98+
---
99+
100+
1. Open *Program.cs* and add the following namespaces:
101+
102+
103+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
104+
```csharp
105+
using Microsoft.Extensions.Configuration;
106+
using Microsoft.Azure.AppConfiguration.AspNetCore;
107+
using Azure.Identity;
108+
```
109+
110+
### [Connection string](#tab/connection-string)
111+
```csharp
112+
using Microsoft.Extensions.Configuration;
113+
using Microsoft.Azure.AppConfiguration.AspNetCore;
114+
```
115+
---
116+
117+
1. Connect to your App Configuration store by calling the `AddAzureAppConfiguration` method in the `Program.cs` file.
118+
119+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
120+
121+
You use the `DefaultAzureCredential` to authenticate to your App Configuration store. Follow the [instructions](./concept-enable-rbac.md#authentication-with-token-credentials) to assign your credential the **App Configuration Data Reader** role. Be sure to allow sufficient time for the permission to propagate before running your application.
122+
123+
```csharp
124+
var builder = new ConfigurationBuilder();
125+
builder.AddAzureAppConfiguration(options =>
126+
{
127+
string endpoint = Environment.GetEnvironmentVariable("Endpoint");
128+
options.Connect(new Uri(endpoint), new DefaultAzureCredential());
129+
});
130+
131+
// Load configuration from Azure App Configuration
132+
builder.Configuration.AddAzureAppConfiguration(endpoint);
133+
134+
// The rest of existing code in program.cs
135+
// ... ...
136+
```
137+
138+
This code connects to your App Configuration store using Microsoft Entra ID and load *all* key-values that have *no labels*. For more information on the App Configuration provider, see the [App Configuration provider API reference](/dotnet/api/Microsoft.Extensions.Configuration.AzureAppConfiguration).
67139
68-
1. Open *Program.cs* and add Azure App Configuration as an extra configuration source by calling the `AddAzureAppConfiguration` method.
140+
### [Connection string](#tab/connection-string)
69141
70142
```csharp
71143
var builder = WebApplication.CreateBuilder(args);
@@ -80,7 +152,7 @@ dotnet new webapp --output TestAppConfig --framework net6.0
80152
// ... ...
81153
```
82154
83-
This code will connect to your App Configuration store using a connection string and load *all* key-values that have *no labels*. For more information on the App Configuration provider, see the [App Configuration provider API reference](/dotnet/api/Microsoft.Extensions.Configuration.AzureAppConfiguration).
155+
This code connects to your App Configuration store using a connection string and loads *all* key-values that have *no labels*. For more information on the App Configuration provider, see the [App Configuration provider API reference](/dotnet/api/Microsoft.Extensions.Configuration.AzureAppConfiguration).
84156
85157
## Read from the App Configuration store
86158

0 commit comments

Comments
 (0)