Skip to content

Commit 9fbfa0c

Browse files
committed
Add Entra ID tab
1 parent b5c8c76 commit 9fbfa0c

File tree

1 file changed

+77
-3
lines changed

1 file changed

+77
-3
lines changed

articles/azure-app-configuration/enable-dynamic-configuration-dotnet.md

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.service: azure-app-configuration
77
ms.devlang: csharp
88
ms.custom: devx-track-csharp, devx-track-dotnet
99
ms.topic: tutorial
10-
ms.date: 03/07/2024
10+
ms.date: 03/06/2025
1111
ms.author: malev
1212
#Customer intent: I want to dynamically update my .NET Framework app to use the latest configuration data in App Configuration.
1313
---
@@ -63,9 +63,50 @@ Add the following key-value to the App Configuration store and leave **Label** a
6363
private static IConfigurationRefresher _refresher;
6464
```
6565

66-
1. Update the `Main` method to connect to App Configuration with the specified refresh options.
66+
1. Update the `Main` method to connect to App Configuration with the specified refresh options. Connect to App Configuration using Microsoft Entra ID (recommended), or a connection string.
6767

68+
69+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
70+
71+
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.
72+
6873
```csharp
74+
// Existing code in Program.cs
75+
// ... ...
76+
77+
static void Main(string[] args)
78+
{
79+
var builder = new ConfigurationBuilder();
80+
builder.AddAzureAppConfiguration(options =>
81+
{
82+
string endpoint = Environment.GetEnvironmentVariable("Endpoint");
83+
options.Connect(new Uri(endpoint), new DefaultAzureCredential());
84+
// Load all keys that start with `TestApp:`.
85+
.Select("TestApp:*")
86+
// Configure to reload the key 'TestApp:Settings:Message' if it is modified.
87+
.ConfigureRefresh(refresh =>
88+
{
89+
refresh.Register("TestApp:Settings:Message")
90+
.SetCacheExpiration(TimeSpan.FromSeconds(10));
91+
});
92+
93+
_refresher = options.GetRefresher();
94+
});
95+
96+
_configuration = builder.Build();
97+
PrintMessage().Wait();
98+
}
99+
100+
// The rest of existing code in Program.cs
101+
// ... ...
102+
```
103+
104+
### [Connection string](#tab/connection-string)
105+
106+
```csharp
107+
// Existing code in Program.cs
108+
// ... ...
109+
69110
static void Main(string[] args)
70111
{
71112
var builder = new ConfigurationBuilder();
@@ -110,7 +151,33 @@ Add the following key-value to the App Configuration store and leave **Label** a
110151

111152
## Build and run the app locally
112153

113-
1. Set an environment variable named **ConnectionString** to the read-only key connection string obtained during your App Configuration store creation.
154+
1. Set an environment variable.
155+
156+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
157+
158+
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.
159+
160+
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
161+
162+
```cmd
163+
setx Endpoint "<endpoint-of-your-app-configuration-store>"
164+
```
165+
166+
If you use PowerShell, run the following command:
167+
168+
```powershell
169+
$Env:Endpoint = "<endpoint-of-your-app-configuration-store>"
170+
```
171+
172+
If you use macOS or Linux, run the following command:
173+
174+
```bash
175+
export Endpoint='<endpoint-of-your-app-configuration-store>'
176+
```
177+
178+
### [Connection string](#tab/connection-string)
179+
180+
Set an environment variable named `ConnectionString` to the read-only key connection string found under **Access keys** of your store in the Azure portal.
114181

115182
If you use the Windows command prompt, run the following command:
116183
```console
@@ -122,6 +189,13 @@ Add the following key-value to the App Configuration store and leave **Label** a
122189
$Env:ConnectionString = "<connection-string-of-your-app-configuration-store>"
123190
```
124191

192+
If you use macOS or Linux, run the following command:
193+
194+
```bash
195+
export ConnectionString='<connection-string-of-your-app-configuration-store>'
196+
```
197+
---
198+
125199
1. Restart Visual Studio to allow the change to take effect.
126200

127201
1. Press Ctrl + F5 to build and run the console app.

0 commit comments

Comments
 (0)