Skip to content

Commit 5703f8b

Browse files
committed
Add DefaultAzureCredential intro
1 parent cf200d2 commit 5703f8b

File tree

1 file changed

+39
-37
lines changed

1 file changed

+39
-37
lines changed

articles/azure-app-configuration/howto-targetingfilter-aspnet-core.md

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ In this guide, you'll use the targeting filter to roll out a feature to a target
2323

2424
## Create a web application with a feature flag
2525

26-
In this section, you will create a web application that allows users to sign in and use the *Beta* feature flag you created before.
26+
In this section, you create a web application that allows users to sign in and use the *Beta* feature flag you created before.
2727

2828
1. Create a web application that authenticates against a local database using the following command.
2929

@@ -37,11 +37,11 @@ In this section, you will create a web application that allows users to sign in
3737
cd TestFeatureFlags
3838
```
3939

40-
1. Connect to your App Configuration store using Microsoft Entra ID (recommended), or a connection string.
40+
1. Add references to the following NuGet packages to connect to your App Configuration store using Microsoft Entra ID (recommended) or a connection string.
4141

4242
### [Microsoft Entra ID (recommended)](#tab/entra-id)
4343

44-
Add references to the following NuGet packages.
44+
Add references to the following NuGet packages.
4545

4646
```dotnetcli
4747
dotnet add package Microsoft.Azure.AppConfiguration.AspNetCore
@@ -59,7 +59,7 @@ In this section, you will create a web application that allows users to sign in
5959
```
6060
---
6161
62-
1. Run the following command to restore packages for your project:
62+
1. Restore packages for your project:
6363
6464
```dotnetcli
6565
dotnet restore
@@ -89,40 +89,42 @@ In this section, you will create a web application that allows users to sign in
8989
1. Add Azure App Configuration and feature management to your application.
9090
9191
### [Microsoft Entra ID (recommended)](#tab/entra-id)
92+
93+
1. 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.
9294
93-
Update the *Program.cs* file with the following code.
94-
95-
``` C#
96-
// Existing code in Program.cs
97-
// ... ...
98-
99-
using Azure.Identity;
100-
101-
var builder = WebApplication.CreateBuilder(args);
102-
103-
// Load configuration from Azure App Configuration
104-
builder.Configuration.AddAzureAppConfiguration(options =>
105-
{
106-
string endpoint = builder.Configuration.Get("Endpoints:AppConfiguration");
107-
options.Connect(new Uri(endpoint), new DefaultAzureCredential());
108-
});
109-
110-
// Load feature flag configuration from Azure App Configuration
111-
builder.Configuration.AddAzureAppConfiguration(options =>
112-
{
113-
options.Connect(new Uri(endpoint), new DefaultAzureCredential());
114-
options.UseFeatureFlags();
115-
});
116-
117-
// Add Azure App Configuration middleware to the container of services
118-
builder.Services.AddAzureAppConfiguration();
119-
120-
// Add feature management to the container of services
121-
builder.Services.AddFeatureManagement();
122-
123-
// The rest of existing code in Program.cs
124-
// ... ...
125-
```
95+
1. Update the *Program.cs* file with the following code.
96+
97+
``` C#
98+
// Existing code in Program.cs
99+
// ... ...
100+
101+
using Azure.Identity;
102+
103+
var builder = WebApplication.CreateBuilder(args);
104+
105+
// Load configuration from Azure App Configuration
106+
builder.Configuration.AddAzureAppConfiguration(options =>
107+
{
108+
string endpoint = builder.Configuration.Get("Endpoints:AppConfiguration");
109+
options.Connect(new Uri(endpoint), new DefaultAzureCredential());
110+
});
111+
112+
// Load feature flag configuration from Azure App Configuration
113+
builder.Configuration.AddAzureAppConfiguration(options =>
114+
{
115+
options.Connect(new Uri(endpoint), new DefaultAzureCredential());
116+
options.UseFeatureFlags();
117+
});
118+
119+
// Add Azure App Configuration middleware to the container of services
120+
builder.Services.AddAzureAppConfiguration();
121+
122+
// Add feature management to the container of services
123+
builder.Services.AddFeatureManagement();
124+
125+
// The rest of existing code in Program.cs
126+
// ... ...
127+
```
126128
127129
### [Connection string](#tab/connection-string)
128130

0 commit comments

Comments
 (0)