You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-app-configuration/howto-targetingfilter-aspnet-core.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -133,7 +133,7 @@ In this section, you will create a web application that allows users to sign in
133
133
134
134
1. Open *_Layout.cshtml* in the *Pages/Shared* directory. Insert a new `<feature>` tag in between the *Home* and *Privacy* navbar items, as shown in the highlighted lines below.
Copy file name to clipboardExpand all lines: articles/azure-app-configuration/howto-targetingfilter.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,7 +68,7 @@ In this article, you will learn how to add and configure a targeting filter for
68
68
> [!div class="mx-imgBorder"]
69
69
> 
70
70
71
-
Now, you successfully added a targeting filter for your feature flag. This targeting filter will use the targeting rule you configured to enable or disable the feature flag for specific users and groups. Follow the instructions in the [Next Steps](#next-steps) section to learn how it works in your application for the language or platform you are using.
71
+
Now, you successfully added a targeting filter for your feature flag. This targeting filter will use the targeting rule you configured to enable or disable the feature flag for specific users and groups. Follow the instructions in the [Next steps](#next-steps) section to learn how it works in your application for the language or platform you are using.
Copy file name to clipboardExpand all lines: articles/azure-app-configuration/use-feature-flags-dotnet-core.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -129,18 +129,18 @@ By convention, the `FeatureManagement` section of this JSON document is used for
129
129
*`FeatureB` is *off*.
130
130
*`FeatureC` specifies a filter named `Percentage` with a `Parameters` property. `Percentage` is a configurable filter. In this example, `Percentage` specifies a 50-percent probability for the `FeatureC` flag to be *on*. For a how-to guide on using feature filters, see [Use feature filters to enable conditional feature flags](./howto-feature-filters-aspnet-core.md).
131
131
132
-
## Use dependency injection to access IVariantFeatureManager
132
+
## Use dependency injection to access IFeatureManager
133
133
134
-
For some operations, such as manually checking feature flag values, you need to get an instance of `IVariantFeatureManager`. In ASP.NET Core MVC, you can access the feature manager `IVariantFeatureManager` through dependency injection. In the following example, an argument of type `IVariantFeatureManager` is added to the signature of the constructor for a controller. The runtime automatically resolves the reference and provides an implementation of the interface when calling the constructor. If you're using an application template in which the controller already has one or more dependency injection arguments in the constructor, such as `ILogger`, you can just add `IVariantFeatureManager` as an additional argument:
134
+
For some operations, such as manually checking feature flag values, you need to get an instance of [IFeatureManager](/dotnet/api/microsoft.featuremanagement.ifeaturemanager). In ASP.NET Core MVC, you can access the feature manager `IFeatureManager` through dependency injection. In the following example, an argument of type `IFeatureManager` is added to the signature of the constructor for a controller. The runtime automatically resolves the reference and provides an implementation of the interface when calling the constructor. If you're using an application template in which the controller already has one or more dependency injection arguments in the constructor, such as `ILogger`, you can just add `IFeatureManager` as an additional argument:
Copy file name to clipboardExpand all lines: articles/azure-app-configuration/use-variant-feature-flags-aspnet-core.md
+42-58Lines changed: 42 additions & 58 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,62 +13,50 @@ ms.date: 10/10/2024
13
13
14
14
# Tutorial: Use variant feature flags from Azure App Configuration in an ASP.NET application
15
15
16
-
In this tutorial, you:
16
+
In this tutorial, you'll use a variant feature flag to manage experiences for different user segments in an example application, *Quote of the Day*. You'll utilize the variant feature flag created in [Use variant feature flags](./use-variant-feature-flags.md). Before proceeding, ensure you create the variant feature flag named *Greeting* in your App Configuration store.
17
17
18
18
> [!div class="checklist"]
19
-
> * Create a variant feature flag
20
-
> * Set up an app to consume variant feature flags
19
+
> * Set up an ASP.NET app to consume variant feature flags
21
20
22
21
## Prerequisites
23
22
24
23
* An Azure subscription. If you don’t have one, [create one for free](https://azure.microsoft.com/free/).
25
24
* An [App Configuration store](./quickstart-azure-app-configuration-create.md).
Create a variant feature flag called *Greeting* with no label and three variants, *None*, *Simple*, and *Long*. Creating variant flags is described in the [Feature Flag quickstart](./manage-feature-flags.md#create-a-variant-feature-flag).
30
-
31
-
| Variant Name | Variant Configuration Value | Allocation|
32
-
|---|---|---|
33
-
| None *(Default)*| null | 50% |
34
-
| Simple | "Hello!" | 25% |
35
-
| Long | "I hope this makes your day!" | 25% |
36
-
37
-
## Set up an app to use the variants
38
-
39
-
In this example, you create an ASP.NET web app named _Quote of the Day_. When the app is loaded, it displays a quote. Users can interact with the heart button to like it. To improve user engagement, you want to explore whether a personalized greeting message will increase the number of users who like the quote. Users who receive the _None_ variant will see no greeting. Users who receive the _Simple_ variant will get a simple greeting message. Users who receive the _Long_ variant will get a slightly longer greeting.
40
-
41
-
### Create an app and add user secrets
27
+
### Create an ASP.NET Core web app
42
28
43
29
1. Open a command prompt and run the following code. This creates a new Razor Pages application in ASP.NET Core, using Individual account auth, and places it in an output folder named *QuoteOfTheDay*.
44
30
45
31
```dotnetcli
46
32
dotnet new razor --auth Individual -o QuoteOfTheDay
47
33
```
48
34
49
-
1. In the command prompt, navigate to the *QuoteOfTheDay* folder and run the following command to create a [user secret](/aspnet/core/security/app-secrets) for the application. This secret holds the connection string for App Configuration.
35
+
1. In the command prompt, navigate to the *QuoteOfTheDay* folder and run the following command to create a [user secret](/aspnet/core/security/app-secrets) for the application. This secret holds the endpoint for App Configuration.
50
36
51
37
```dotnetcli
52
-
dotnet user-secrets set ConnectionStrings:AppConfiguration "<App Configuration Connection string>"
38
+
dotnet user-secrets set Endpoints:AppConfiguration "<App Configuration Endpoint>"
53
39
```
54
40
55
-
### Update the application code
56
-
57
-
1. In *QuoteOfTheDay.csproj*, add the latest versions of the Feature Management and App Configuration SDKs as required packages.
41
+
1. Add the latest versions of the required libraries.
1. In *Program.cs*, under the line `var builder = WebApplication.CreateBuilder(args);`, add the App Configuration provider, which pulls down the configuration from Azure when the application starts. By default, the UseFeatureFlags method includes all feature flags with no label.
49
+
## Connect to App Configuration for feature management
50
+
51
+
1. In *Program.cs*, under the line `var builder = WebApplication.CreateBuilder(args);`, add the App Configuration provider, which pulls down the configuration from Azure App Configuration when the application starts. See the [.NET provider quickstart](./quickstart-dotnet-core-app?tabs=entra-id#connect-to-an-app-configuration-store) for more on authenticating with the provider. By default, the UseFeatureFlags method includes all feature flags with no label.
options.Connect(new Uri(endpoint), new DefaultAzureCredential());
59
+
72
60
options.UseFeatureFlags();
73
61
});
74
62
```
@@ -79,7 +67,7 @@ In this example, you create an ASP.NET web app named _Quote of the Day_. When th
79
67
using Microsoft.FeatureManagement;
80
68
```
81
69
82
-
1. Set up Feature Management and enable Feature Management Targeting.
70
+
1. Add Azure App Configuration and feature management services and enable targeting for feature management.
83
71
84
72
```csharp
85
73
// Add Azure App Configuration and feature management services to the container.
@@ -88,20 +76,22 @@ In this example, you create an ASP.NET web app named _Quote of the Day_. When th
88
76
.WithTargeting();
89
77
```
90
78
91
-
1. Under the line `var app = builder.Build();`, add a middleware that triggers App Configuration refresh when appropriate.
79
+
1. Under the line `var app = builder.Build();`, add Azure App Configuration middleware for dynamic configuration refresh.
92
80
93
81
```csharp
94
82
// Use Azure App Configuration middleware for dynamic configuration refresh.
95
83
app.UseAzureAppConfiguration();
96
84
```
97
85
98
-
1. In *QuoteOfTheDay* > *Pages* > *Shared* > *_Layout.cshtml*, under where `QuoteOfTheDay.styles.css` is added, add the following line to add the css for version 5.15.3 of `font-awesome`.
86
+
## Use the variant feature flag
87
+
88
+
1. In *QuoteOfTheDay* > *Pages* > *Shared* > *_Layout.cshtml*, under where `QuoteOfTheDay.styles.css` is added, add the following reference to the font-awesome CSS library.
@@ -164,16 +154,16 @@ In this example, you create an ASP.NET web app named _Quote of the Day_. When th
164
154
}
165
155
```
166
156
167
-
This `PageModel` picks a random quote, uses `GetVariantAsync` to get the variant for the current user, and sets a variable called "Greeting" to the variant's value. The `PageModel` also handles likes, which are sent as post requests.
157
+
This `PageModel` picks a random quote, uses `GetVariantAsync` to get the variant for the current user, and sets a variable called "GreetingMessage" to the variant's value. The `PageModel` also handles likes, which are sent as post requests.
168
158
169
-
1. Open *index.cshtml* and overwrite the content for the quote app.
159
+
1. Open *index.cshtml* and replace its content with the following code.
@@ -278,14 +261,17 @@ In this example, you create an ASP.NET web app named _Quote of the Day_. When th
278
261
</script>
279
262
```
280
263
281
-
This code corresponds to the UI to show the QuoteOfTheDay and handle using the heart action on a quote. It uses the previously mentioned `Model.ShowGreeting` value to show different things to different users, depending on their variant.
264
+
This code corresponds to the UI to show the QuoteOfTheDay and handle using the heart action on a quote. It uses the previously mentioned `Model.GreetingMessage` value to show different things to different users, depending on their variant.
282
265
283
266
### Build and run the app
284
267
285
-
1. In the command prompt, in the *QuoteOfTheDay* folder, run: `dotnet build`.
286
-
1. Run: `dotnet run --launch-profile https`.
287
-
1. Look for a message in the format `Now listening on: https://localhost:{port}` in the output of the application. Navigate to the included link in your browser.
288
-
1. Once viewing the running application, select **Register** at the top right to register a new user.
268
+
1. Build and run the application.
269
+
270
+
```dotnetcli
271
+
dotnet build
272
+
dotnet run
273
+
```
274
+
1. Once the application is loaded, select **Register** at the top right to register a new user.
289
275
290
276
:::image type="content" source="media/use-variant-feature-flags-aspnet-core/register.png" alt-text="Screenshot of the Quote of the day app, showing Register.":::
291
277
@@ -295,21 +281,19 @@ In this example, you create an ASP.NET web app named _Quote of the Day_. When th
295
281
296
282
:::image type="content" source="media/use-variant-feature-flags-aspnet-core/click-to-confirm.png" alt-text="Screenshot of the Quote of the day app, showing click to confirm.":::
297
283
298
-
1. Register a second user named *[email protected]*, enter another password, and validate this second email.
284
+
1. Repeat the same steps to register a second user named [email protected].
299
285
300
286
> [!NOTE]
301
287
> It's important for the purpose of this tutorial to use these names exactly. As long as the feature has been configured as expected, the two users should see different variants.
302
-
303
-
1. Select **Login** at the top right to sign in as userb (userb@contoso.com).
288
+
@
289
+
1. Select **Login** at the top right to sign in as usera@contoso.com.
304
290
305
291
:::image type="content" source="media/use-variant-feature-flags-aspnet-core/login.png" alt-text="Screenshot of the Quote of the day app, showing **Login**.":::
306
292
307
293
1. Once logged in, you should see that [email protected] sees the long message when viewing the app, and [email protected] sees the simple message.
308
294
309
295
:::image type="content" source="media/use-variant-feature-flags-aspnet-core/special-message.png" alt-text="Screenshot of the Quote of the day app, showing a special message for the user.":::
0 commit comments