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-feature-filters-aspnet-core.md
+25-26Lines changed: 25 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,17 @@
1
1
---
2
2
title: Use feature filters to enable conditional feature flags
3
3
titleSuffix: Azure App Configuration
4
-
description: Learn how to use feature filters to enable conditional feature flags
4
+
description: Learn how to use feature filters in Azure App Configuration to enable conditional feature flags for your app.
5
5
ms.service: azure-app-configuration
6
6
ms.devlang: csharp
7
7
ms.custom: devx-track-csharp
8
8
author: maud-lv
9
9
ms.author: malev
10
-
ms.topic: conceptual
11
-
ms.date: 3/9/2020
10
+
ms.topic: how-to
11
+
ms.date: 01/12/2024
12
+
#Customerintent: As a developer, I want to create a feature filter to activate a feature flag depending on a specific scenario.
12
13
---
14
+
13
15
# Use feature filters to enable conditional feature flags
14
16
15
17
Feature flags allow you to activate or deactivate functionality in your application. A simple feature flag is either on or off. The application always behaves the same way. For example, you could roll out a new feature behind a feature flag. When the feature flag is enabled, all users see the new feature. Disabling the feature flag hides the new feature.
@@ -24,7 +26,11 @@ The `Microsoft.FeatureManagement` library includes three feature filters:
24
26
25
27
You can also create your own feature filter that implements the Microsoft.FeatureManagement.IFeatureFilter interface.
26
28
27
-
## Registering a feature filter
29
+
## Prerequisites
30
+
31
+
- An App Configuration store. [Create a store](./quickstart-azure-app-configuration-create.md#create-an-app-configuration-store).
32
+
33
+
## Register a feature filter
28
34
29
35
You register a feature filter by calling the `AddFeatureFilter` method, specifying the type name of the desired feature filter. For example, the following code registers `PercentageFilter`:
30
36
@@ -36,51 +42,44 @@ public void ConfigureServices(IServiceCollection services)
36
42
}
37
43
```
38
44
39
-
## Configuring a feature filter in Azure App Configuration
45
+
## Configure a feature filter in Azure App Configuration
40
46
41
47
Some feature filters have additional settings. For example, `PercentageFilter` activates a feature based on a percentage. It has a setting defining the percentage to use.
42
48
43
49
You can configure these settings for feature flags defined in Azure App Configuration. For example, follow these steps to use `PercentageFilter` to enable the feature flag for 50% of requests to a web app:
44
50
45
51
1. Follow the instructions in [Quickstart: Add feature flags to an ASP.NET Core app](./quickstart-feature-flag-aspnet-core.md) to create a web app with a feature flag.
46
52
47
-
1. In the Azure portal, go to your configuration store and click **Feature manager**.
48
-
49
-
1. Click on the context menu for the *Beta* feature flag that you created in the quickstart. Click **Edit**.
53
+
1. In the Azure portal, go to your configuration store and select **Feature manager**.
:::image type="content" source="./media/feature-filters/edit-beta-feature-flag.png" alt-text="Screenshot of the Azure portal, selecting the Edit option for the Beta feature flag, under Feature manager.":::
53
56
54
-
1.In the **Edit** screen, check the **Enable feature flag** checkbox if it isn't already enabled. Then check the **Use feature filter** checkbox and select**Custom**.
57
+
1.On the line with the Beta feature flag you created in the quickstart, select the context menu and then**Edit**.
55
58
56
-
1. In the **Name**field, select *Microsoft.Percentage*.
59
+
1. In the **Edit feature flag**pane that opens, check the **Enable feature flag** checkbox if it isn't already enabled. Then check the **Use feature filter** checkbox and select **Create**.
:::image type="content" source="./media/feature-filters/edit-a-feature-flag.png" alt-text="Screenshot of the Azure portal, filling out the form 'Edit feature flag'.":::
60
62
61
-
1.Click the context menu next to the feature filter name. Click**Edit filter parameters**.
63
+
1.The pane **Create a new filter** opens. Under **Filter type**, select**Targeting filter** to enable a new filter for specific users or a group.
:::image type="content" source="./media/feature-filters/add-targeting-filter.png" alt-text="Screenshot of the Azure portal, creating a new targeting filter.":::
65
66
66
-
1. Enter a **Name** of *Value* and a **Value** of 50. The **Value** field indicates the percentage of requests for which to enable the feature filter.
67
+
1. Optionally expand the **Evaluation flow** menu to see a graph showing how the targeting filter is evaluated in the selected scenario. Leave the **Default Percentage** at 50. The options **Override by Groups** and **Override by Users** let you enable or disable the feature flag for select groups or users. These options are disabled by default.
68
+
1. Select **Add** to save the new feature filter and return to the **Edit feature flag** screen.
1. The feature filter you created is now listed in the feature flag details. Select **Apply** to save the new feature flag settings.
70
71
71
-
1. Click **Apply** to return to the **Edit featureflag** screen. Then click **Apply** again to save the feature flag settings.
72
+
:::image type="content" source="./media/feature-filters/feature-flag-edit-apply-filter.png" alt-text="Screenshot of the Azure portal, applying new targeting filter.":::
72
73
73
-
1. On the **Feature manager** page, the feature flag now has a **Feature filter** value of *Custom*.
74
+
1. On the **Feature manager** page, the feature flag now has a **Feature filter(s)** value of **1**.
74
75
75
-
> [!div class="mx-imgBorder"]
76
-
> 
76
+
:::image type="content" source="./media/feature-filters/updated-feature-flag.png" alt-text="Screenshot of the Azure portal, displaying updated feature flag.":::
77
77
78
78
## Feature filters in action
79
79
80
80
To see the effects of this feature flag, launch the application and hit the **Refresh** button in your browser multiple times. You'll see that the *Beta* item appears on the toolbar about 50% of the time. It's hidden the rest of the time, because the `PercentageFilter` deactivates the *Beta* feature for a subset of requests. The following video shows this behavior in action.
81
81
82
-
> [!div class="mx-imgBorder"]
83
-
> 
82
+
:::image type="content" source="./media/feature-filters/feature-flags-percentagefilter.gif" alt-text="Screenshot of a web browser showing a targeting filter in action.":::
0 commit comments