Skip to content

Commit 305e895

Browse files
committed
Resolving comments
1 parent 85bbce5 commit 305e895

File tree

5 files changed

+87
-79
lines changed

5 files changed

+87
-79
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ In this section, you will create a web application that allows users to sign in
133133
134134
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.
135135
136-
:::code language="html" source="../../includes/azure-app-configuration-navbar.md" range="14-38" highlight="13-17":::
136+
:::code language="html" source="../../includes/azure-app-configuration-navbar.md" range="15-39" highlight="13-17":::
137137
138138
## Enable targeting for the web application
139139

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ In this article, you will learn how to add and configure a targeting filter for
6868
> [!div class="mx-imgBorder"]
6969
> ![Screenshot of the Azure portal, applying new targeting filter.](./media/feature-filters/feature-flag-edit-apply-targeting-filter.png)
7070
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.
7272

7373
## Next steps
7474

articles/azure-app-configuration/use-feature-flags-dotnet-core.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,18 @@ By convention, the `FeatureManagement` section of this JSON document is used for
129129
* `FeatureB` is *off*.
130130
* `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).
131131

132-
## Use dependency injection to access IVariantFeatureManager
132+
## Use dependency injection to access IFeatureManager
133133

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:
135135

136136
```csharp
137137
using Microsoft.FeatureManagement;
138138

139139
public class HomeController : Controller
140140
{
141-
private readonly IVariantFeatureManager _featureManager;
141+
private readonly IFeatureManager _featureManager;
142142

143-
public HomeController(ILogger<HomeController> logger, IVariantFeatureManager featureManager)
143+
public HomeController(ILogger<HomeController> logger, IFeatureManager featureManager)
144144
{
145145
_featureManager = featureManager;
146146
}
@@ -165,7 +165,7 @@ public static class MyFeatureFlags
165165
A common pattern of feature management is to check if a feature flag is set to *on* and if so, run a section of code. For example:
166166

167167
```csharp
168-
IVariantFeatureManager featureManager;
168+
IFeatureManager featureManager;
169169
...
170170
if (await featureManager.IsEnabledAsync(MyFeatureFlags.FeatureA))
171171
{

articles/azure-app-configuration/use-variant-feature-flags-aspnet-core.md

Lines changed: 42 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -13,62 +13,50 @@ ms.date: 10/10/2024
1313

1414
# Tutorial: Use variant feature flags from Azure App Configuration in an ASP.NET application
1515

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.
1717

1818
> [!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
2120
2221
## Prerequisites
2322

2423
* An Azure subscription. If you don’t have one, [create one for free](https://azure.microsoft.com/free/).
2524
* An [App Configuration store](./quickstart-azure-app-configuration-create.md).
25+
* [Use variant feature flags](./use-variant-feature-flags.md)
2626

27-
## Create a variant feature flag
28-
29-
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
4228

4329
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*.
4430

4531
```dotnetcli
4632
dotnet new razor --auth Individual -o QuoteOfTheDay
4733
```
4834
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.
5036
5137
```dotnetcli
52-
dotnet user-secrets set ConnectionStrings:AppConfiguration "<App Configuration Connection string>"
38+
dotnet user-secrets set Endpoints:AppConfiguration "<App Configuration Endpoint>"
5339
```
5440
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.
5842
59-
```csharp
60-
<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="8.0.0" />
61-
<PackageReference Include="Microsoft.FeatureManagement.AspNetCore" Version="4.0.0" />
43+
```dotnetcli
44+
dotnet add package Azure.Identity
45+
dotnet add package Microsoft.Extensions.Configuration.AzureAppConfiguration
46+
dotnet add package Microsoft.FeatureManagement.AspNetCore
6247
```
6348
64-
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.
6552
6653
```csharp
6754
builder.Configuration
6855
.AddAzureAppConfiguration(options =>
6956
{
70-
options.Connect(builder.Configuration.GetConnectionString("AppConfiguration"));
71-
57+
string endpoint = builder.Configuration.Get("Endpoints:AppConfiguration");
58+
options.Connect(new Uri(endpoint), new DefaultAzureCredential());
59+
7260
options.UseFeatureFlags();
7361
});
7462
```
@@ -79,7 +67,7 @@ In this example, you create an ASP.NET web app named _Quote of the Day_. When th
7967
using Microsoft.FeatureManagement;
8068
```
8169
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.
8371
8472
```csharp
8573
// 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
8876
.WithTargeting();
8977
```
9078
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.
9280
9381
```csharp
9482
// Use Azure App Configuration middleware for dynamic configuration refresh.
9583
app.UseAzureAppConfiguration();
9684
```
9785
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.
9989
10090
```css
10191
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
10292
```
10393
104-
1. Open *QuoteOfTheDay* > *Pages* > *Index.cshtml.cs* and overwrite the content to the quote app.
94+
1. Open *QuoteOfTheDay* > *Pages* > *Index.cshtml.cs* and replace the content with the following code.
10595
10696
```csharp
10797
using Microsoft.AspNetCore.Mvc;
@@ -130,7 +120,7 @@ In this example, you create an ASP.NET web app named _Quote of the Day_. When th
130120
131121
public Quote? Quote { get; set; }
132122
133-
public string Greeting { get; set; }
123+
public string GreetingMessage { get; set; }
134124
135125
public async void OnGet()
136126
{
@@ -140,7 +130,7 @@ In this example, you create an ASP.NET web app named _Quote of the Day_. When th
140130
141131
if (variant != null)
142132
{
143-
Greeting = variant.Configuration?.Get<string>() ?? "";
133+
GreetingMessage = variant.Configuration?.Get<string>() ?? "";
144134
}
145135
else
146136
{
@@ -164,16 +154,16 @@ In this example, you create an ASP.NET web app named _Quote of the Day_. When th
164154
}
165155
```
166156
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.
168158
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.
170160
171161
```cshtml
172162
@page
173163
@model IndexModel
174164
@{
175165
ViewData["Title"] = "Home page";
176-
ViewData["Username"] = User.Identity.Name;
166+
ViewData["Username"] = User.Identity?.Name ?? string.Empty;
177167
}
178168
179169
<style>
@@ -233,17 +223,10 @@ In this example, you create an ASP.NET web app named _Quote of the Day_. When th
233223
234224
<div class="quote-container">
235225
<div class="quote-content">
236-
@if (Model.ShowGreeting)
237-
{
238-
<h3 class="greeting-content">Hi <b>@User.Identity.Name</b>, hope this makes your day!</h3>
239-
}
240-
else
241-
{
242-
<h3 class="greeting-content">Quote of the day</h3>
243-
}
226+
<h3 class="greeting-content">@(Model.GreetingMessage)</h3>
244227
<br />
245-
<p class="quote">“@Model.Quote.Message”</p>
246-
<p>- <b>@Model.Quote.Author</b></p>
228+
<p class="quote">“@(Model.Quote?.Message ?? "< Quote not found >")”</p>
229+
<p>- <b>@(Model.Quote?.Author ?? "Unknown")</b></p>
247230
</div>
248231
249232
<div class="vote-container">
@@ -278,14 +261,17 @@ In this example, you create an ASP.NET web app named _Quote of the Day_. When th
278261
</script>
279262
```
280263
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.
282265
283266
### Build and run the app
284267
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.
289275
290276
:::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.":::
291277
@@ -295,21 +281,19 @@ In this example, you create an ASP.NET web app named _Quote of the Day_. When th
295281
296282
:::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.":::
297283
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].
299285
300286
> [!NOTE]
301287
> 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.
304290
305291
:::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**.":::
306292
307293
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.
308294
309295
:::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.":::
310296
311-
*[email protected]* sees the long message.
312-
313297
## Next steps
314298
315299
To learn more about the experimentation concepts, refer to the following document.

0 commit comments

Comments
 (0)