Skip to content

Commit cd1fa5b

Browse files
committed
Add Entra ID tab to quickstart-feature-flag-dotnet
1 parent 5c1a771 commit cd1fa5b

File tree

1 file changed

+95
-14
lines changed

1 file changed

+95
-14
lines changed

articles/azure-app-configuration/quickstart-feature-flag-dotnet.md

Lines changed: 95 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ms.devlang: csharp
99
ms.custom: devx-track-csharp, mode-other, devx-track-dotnet
1010
ms.topic: quickstart
1111
ms.tgt_pltfrm: .NET
12-
ms.date: 2/19/2024
12+
ms.date: 2/13/2025
1313
ms.author: zhiyuanliang
1414
#Customer intent: As a .NET developer, I want to use feature flags to control feature availability quickly and confidently.
1515
---
@@ -63,9 +63,68 @@ You can use Visual Studio to create a new console app project.
6363
using Microsoft.FeatureManagement;
6464
```
6565
66-
1. Connect to App Configuration, specifying the `UseFeatureFlags` option so that feature flags are retrieved. Create a `ConfigurationFeatureDefinitionProvider` to provide feature flag definition from the configuration and a `FeatureManager` to evaluate feature flags' state. Then display a message if the `Beta` feature flag is enabled.
66+
1. Update *Program.cs*. to connect to your App Configuration store using Microsoft Entra ID (recommended) or a connection string, and specify the `UseFeatureFlags` option so that feature flags are retrieved. Create a `ConfigurationFeatureDefinitionProvider` to provide feature flag definition from the configuration and a `FeatureManager` to evaluate feature flags' state. Then display a message if the `Beta` feature flag is enabled.
6767
68-
### [.NET](#tab/dotnet)
68+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
69+
70+
You use the `DefaultAzureCredential` to authenticate to your App Configuration store by default. 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.
71+
72+
#### .NET
73+
74+
```csharp
75+
IConfiguration configuration = new ConfigurationBuilder()
76+
.AddAzureAppConfiguration(options =>
77+
{
78+
string endpoint = Environment.GetEnvironmentVariable("Endpoint");
79+
options.Connect(new Uri(endpoint), new DefaultAzureCredential());
80+
.UseFeatureFlags();
81+
}).Build();
82+
83+
IFeatureDefinitionProvider featureDefinitionProvider = new ConfigurationFeatureDefinitionProvider(configuration);
84+
85+
IVariantFeatureManager featureManager = new FeatureManager(
86+
featureDefinitionProvider,
87+
new FeatureManagementOptions());
88+
89+
if (await featureManager.IsEnabledAsync("Beta"))
90+
{
91+
Console.WriteLine("Welcome to the beta!");
92+
}
93+
94+
Console.WriteLine("Hello World!");
95+
```
96+
97+
#### .NET Framework
98+
99+
```csharp
100+
public static async Task Main(string[] args)
101+
{
102+
IConfiguration configuration = new ConfigurationBuilder()
103+
.AddAzureAppConfiguration(options =>
104+
{
105+
string endpoint = Environment.GetEnvironmentVariable("Endpoint");
106+
options.Connect(new Uri(endpoint), new DefaultAzureCredential());
107+
.UseFeatureFlags();
108+
}).Build();
109+
110+
IFeatureDefinitionProvider featureDefinitionProvider = new ConfigurationFeatureDefinitionProvider(configuration);
111+
112+
IVariantFeatureManager featureManager = new FeatureManager(
113+
featureDefinitionProvider,
114+
new FeatureManagementOptions());
115+
116+
if (await featureManager.IsEnabledAsync("Beta"))
117+
{
118+
Console.WriteLine("Welcome to the beta!");
119+
}
120+
121+
Console.WriteLine("Hello World!");
122+
}
123+
```
124+
125+
### [Connection string](#tab/connection-string)
126+
127+
#### .NET
69128
70129
```csharp
71130
IConfiguration configuration = new ConfigurationBuilder()
@@ -89,7 +148,7 @@ You can use Visual Studio to create a new console app project.
89148
Console.WriteLine("Hello World!");
90149
```
91150
92-
### [.NET Framework](#tab/dotnet-framework)
151+
#### .NET Framework
93152
94153
```csharp
95154
public static async Task Main(string[] args)
@@ -115,31 +174,53 @@ You can use Visual Studio to create a new console app project.
115174
Console.WriteLine("Hello World!");
116175
}
117176
```
118-
119177
---
120178
121179
## Build and run the app locally
122180
123-
1. Set an environment variable named **ConnectionString** to the connection string of your App Configuration store.
181+
1. Set an environment variable.
124182
125-
### [Windows command prompt](#tab/windowscommandprompt)
183+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
126184
127-
If you use the Windows command prompt, run the following command.
185+
Set an environment variable named **Endpoint** to the endpoint of your App Configuration store found under the **Overview** of your store in the Azure portal.
128186
129-
```console
130-
setx ConnectionString "<connection-string-of-your-app-configuration-store>"
187+
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
188+
189+
```cmd
190+
setx Endpoint "<endpoint-of-your-app-configuration-store>"
191+
```
192+
193+
If you use PowerShell, run the following command:
194+
195+
```powershell
196+
$Env:Endpoint = "<endpoint-of-your-app-configuration-store>"
131197
```
132198
133-
Restart the command prompt to allow the change to take effect. Validate that it's set properly by printing the value of the environment variable.
199+
If you use macOS or Linux, run the following command:
134200
135-
### [PowerShell](#tab/powershell)
201+
```bash
202+
export Endpoint='<endpoint-of-your-app-configuration-store>'
203+
```
204+
205+
### [Connection string](#tab/connection-string)
136206
137-
If you use Windows PowerShell, run the following command.
207+
Set an environment variable named **ConnectionString** to the read-only connection string of your App Configuration store found under **Access settings** of your store in the Azure portal.
138208
139-
```azurepowershell
209+
If you use the Windows command prompt, run the following command:
210+
211+
```console
212+
setx ConnectionString "<connection-string-of-your-app-configuration-store>"
213+
```
214+
If you use Windows PowerShell, run the following command:
215+
```powershell
140216
$Env:ConnectionString = "<connection-string-of-your-app-configuration-store>"
141217
```
142218
219+
If you use macOS or Linux, run the following command:
220+
221+
```bash
222+
export ConnectionString='<connection-string-of-your-app-configuration-store>'
223+
```
143224
---
144225
145226
1. Restart Visual Studio to allow the change to take effect.

0 commit comments

Comments
 (0)