Skip to content

Commit cf200d2

Browse files
committed
Draft tab content
1 parent 9fe441d commit cf200d2

File tree

1 file changed

+86
-5
lines changed

1 file changed

+86
-5
lines changed

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

Lines changed: 86 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ ms.devlang: csharp
77
author: zhiyuanliang-ms
88
ms.author: zhiyuanliang
99
ms.topic: how-to
10-
ms.date: 03/26/2024
10+
ms.date: 12/02/2024
1111
---
1212

1313
# Roll out features to targeted audiences in an ASP.NET Core application
1414

15-
In this guide, you'll use the targeting filter to roll out a feature to targeted audience for your ASP.NET Core application. For more information about the targeting filter, see [Roll out features to targeted audiences](./howto-targetingfilter.md).
15+
In this guide, you'll use the targeting filter to roll out a feature to a targeted audience for your ASP.NET Core application. For more information about the targeting filter, see [Roll out features to targeted audiences](./howto-targetingfilter.md).
1616

1717
## Prerequisites
1818

@@ -31,22 +31,101 @@ In this section, you will create a web application that allows users to sign in
3131
dotnet new webapp --auth Individual -o TestFeatureFlags
3232
```
3333

34-
1. Add references to the following NuGet packages.
34+
1. Navigate to the newly created *TestFeatureFlags* directory.
3535

36+
```dotnetcli
37+
cd TestFeatureFlags
38+
```
39+
40+
1. Connect to your App Configuration store using Microsoft Entra ID (recommended), or a connection string.
41+
42+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
43+
44+
Add references to the following NuGet packages.
45+
46+
```dotnetcli
47+
dotnet add package Microsoft.Azure.AppConfiguration.AspNetCore
48+
dotnet add package Microsoft.FeatureManagement.AspNetCore
49+
dotnet add package Azure.Identity
50+
```
51+
52+
### [Connection string](#tab/connection-string)
53+
54+
Add references to the following NuGet packages.
55+
3656
```dotnetcli
3757
dotnet add package Microsoft.Azure.AppConfiguration.AspNetCore
3858
dotnet add package Microsoft.FeatureManagement.AspNetCore
3959
```
60+
---
61+
62+
1. Run the following command to restore packages for your project:
63+
64+
```dotnetcli
65+
dotnet restore
66+
```
67+
68+
1. Create a user secret for the application by navigating into the *TestFeatureFlags* folder and running the following command.
69+
70+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
71+
72+
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 **Overview** blade in the Azure portal.
73+
74+
```dotnetcli
75+
dotnet user-secrets init
76+
dotnet user-secrets set Endpoints:AppConfiguration "<your-App-Configuration-endpoint>"
77+
```
78+
79+
### [Connection string](#tab/connection-string)
4080
41-
1. Store the connection string for your App Configuration store.
81+
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.
4282
4383
```dotnetcli
4484
dotnet user-secrets init
4585
dotnet user-secrets set ConnectionStrings:AppConfig "<your_connection_string>"
4686
```
87+
---
4788
4889
1. Add Azure App Configuration and feature management to your application.
4990
91+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
92+
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+
```
126+
127+
### [Connection string](#tab/connection-string)
128+
50129
Update the *Program.cs* file with the following code.
51130
52131
``` C#
@@ -75,6 +154,8 @@ In this section, you will create a web application that allows users to sign in
75154
// ... ...
76155
```
77156
157+
---
158+
78159
1. Enable configuration and feature flag refresh from Azure App Configuration with the App Configuration middleware.
79160
80161
Update Program.cs withe the following code.
@@ -104,7 +185,7 @@ In this section, you will create a web application that allows users to sign in
104185
<h1>This is the beta website.</h1>
105186
```
106187
107-
1. Open *Beta.cshtml.cs*, and add `FeatureGate` attribute to the `BetaModel` class.
188+
1. Open *Beta.cshtml.cs*, and add the `FeatureGate` attribute to the `BetaModel` class.
108189
109190
``` C#
110191
using Microsoft.AspNetCore.Mvc.RazorPages;

0 commit comments

Comments
 (0)