Skip to content

Commit 2c13cb5

Browse files
Merge pull request #292102 from zhenlan/endpoint
Fix the code for endpoint retrieval
2 parents 8a78036 + 26e92cb commit 2c13cb5

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

articles/azure-app-configuration/quickstart-aspnet-core-app.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,6 @@ Connect to your App Configuration store using Microsoft Entra ID (recommended),
6464
```
6565
---
6666
67-
1. Run the following command to restore packages for your project:
68-
69-
```dotnetcli
70-
dotnet restore
71-
```
72-
7367
1. Create a user secret for the application by navigating into the *TestAppConfig* folder and running the following command.
7468
7569
### [Microsoft Entra ID (recommended)](#tab/entra-id)
@@ -83,11 +77,11 @@ Connect to your App Configuration store using Microsoft Entra ID (recommended),
8377
8478
### [Connection string](#tab/connection-string)
8579
86-
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.
80+
The command uses [Secret Manager](/aspnet/core/security/app-secrets) to store a secret named `ConnectionStrings:AppConfiguration`, which stores the connection string for your App Configuration store. Replace the `<your-App-Configuration-connection-string>` placeholder with your App Configuration store's read-only connection string. You can find the connection string in your App Configuration store's **Access settings** in the Azure portal.
8781
8882
```dotnetcli
8983
dotnet user-secrets init
90-
dotnet user-secrets set ConnectionStrings:AppConfig "<your_connection_string>"
84+
dotnet user-secrets set ConnectionStrings:AppConfiguration "<your-App-Configuration-connection-string>"
9185
```
9286
9387
> [!TIP]
@@ -124,15 +118,16 @@ Connect to your App Configuration store using Microsoft Entra ID (recommended),
124118
var builder = WebApplication.CreateBuilder(args);
125119
126120
// Retrieve the endpoint
127-
string endpoint = builder.Configuration.Get("Endpoints:AppConfiguration");
128-
121+
string endpoint = builder.Configuration.GetValue<string>("Endpoints:AppConfiguration")
122+
?? throw new InvalidOperationException("The setting `Endpoints:AppConfiguration` was not found.");
123+
129124
// Load configuration from Azure App Configuration
130125
builder.Configuration.AddAzureAppConfiguration(options =>
131126
{
132127
options.Connect(new Uri(endpoint), new DefaultAzureCredential());
133128
});
134129
135-
// The rest of existing code in program.cs
130+
// The rest of existing code in program.cs
136131
// ... ...
137132
```
138133
@@ -142,7 +137,8 @@ Connect to your App Configuration store using Microsoft Entra ID (recommended),
142137
var builder = WebApplication.CreateBuilder(args);
143138
144139
// Retrieve the connection string
145-
string connectionString = builder.Configuration.GetConnectionString("AppConfig");
140+
string connectionString = builder.Configuration.GetConnectionString("AppConfiguration")
141+
?? throw new InvalidOperationException("The connection string 'AppConfiguration' was not found.");
146142
147143
// Load configuration from Azure App Configuration
148144
builder.Configuration.AddAzureAppConfiguration(connectionString);

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

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
2-
title: 'Tutorial: Use variant feature flags from Azure App Configuration in an ASP.NET application'
2+
title: 'Tutorial: Use variant feature flags from Azure App Configuration in an ASP.NET Core application'
33
titleSuffix: Azure App configuration
4-
description: In this tutorial, you learn how to use variant feature flags in an ASP.NET application
4+
description: In this tutorial, you learn how to use variant feature flags in an ASP.NET Core application
55
#customerintent: As a user of Azure App Configuration, I want to learn how I can use variants and variant feature flags in my ASP.NET application.
66
author: rossgrambo
77
ms.author: rossgrambo
88
ms.service: azure-app-configuration
99
ms.devlang: csharp
1010
ms.topic: tutorial
11-
ms.date: 10/18/2024
11+
ms.date: 12/18/2024
1212
---
1313

14-
# Tutorial: Use variant feature flags from Azure App Configuration in an ASP.NET application
14+
# Tutorial: Use variant feature flags in an ASP.NET Core application
1515

1616
In this tutorial, you use a variant feature flag to manage experiences for different user segments in an example application, *Quote of the Day*. You 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

@@ -28,10 +28,11 @@ In this tutorial, you use a variant feature flag to manage experiences for diffe
2828
dotnet new razor --auth Individual -o QuoteOfTheDay
2929
```
3030
31-
1. Create a [user secret](/aspnet/core/security/app-secrets) for the application by navigating into the *QuoteOfTheDay* folder and run the following command. This secret holds the endpoint for your App Configuration.
31+
1. Navigate to the *QuoteOfTheDay* directory and create a [user secret](/aspnet/core/security/app-secrets) for the application by running the following commands. 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.
3232
3333
```dotnetcli
34-
dotnet user-secrets set Endpoints:AppConfiguration "<App Configuration Endpoint>"
34+
dotnet user-secrets init
35+
dotnet user-secrets set Endpoints:AppConfiguration "<your-App-Configuration-endpoint>"
3536
```
3637
3738
1. Add the latest versions of the required packages.
@@ -44,26 +45,31 @@ In this tutorial, you use a variant feature flag to manage experiences for diffe
4445
4546
## Connect to App Configuration for feature management
4647
47-
1. In *Program.cs*, add the following using statements.
48+
1. Open *Program.cs* and add the following using statements.
4849
4950
```csharp
5051
using Azure.Identity;
5152
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
5253
using Microsoft.FeatureManagement;
5354
```
5455
55-
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. By default, the `UseFeatureFlags` method pulls down all feature flags with no label.
56+
1. Add the following code to connect to your App Configuration store and call `UseFeatureFlags` to pull down all feature flags with no label.
5657
5758
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.
5859
5960
```csharp
61+
var builder = WebApplication.CreateBuilder(args);
62+
63+
// Retrieve the endpoint
64+
string endpoint = builder.Configuration.GetValue<string>("Endpoints:AppConfiguration")
65+
?? throw new InvalidOperationException("The setting `Endpoints:AppConfiguration` was not found.");
66+
67+
// Load configuration and feature flags from Azure App Configuration
6068
builder.Configuration
6169
.AddAzureAppConfiguration(options =>
6270
{
63-
string endpoint = builder.Configuration.Get("Endpoints:AppConfiguration");
64-
options.Connect(new Uri(endpoint), new DefaultAzureCredential());
65-
66-
options.UseFeatureFlags();
71+
options.Connect(new Uri(endpoint), new DefaultAzureCredential())
72+
.UseFeatureFlags();
6773
});
6874
```
6975

0 commit comments

Comments
 (0)