@@ -7,7 +7,7 @@ ms.service: azure-app-configuration
7
7
ms.devlang : csharp
8
8
ms.custom : devx-track-csharp, devx-track-dotnet
9
9
ms.topic : tutorial
10
- ms.date : 03/07/2024
10
+ ms.date : 03/06/2025
11
11
ms.author : malev
12
12
# Customer intent: I want to dynamically update my .NET Framework app to use the latest configuration data in App Configuration.
13
13
---
@@ -63,9 +63,50 @@ Add the following key-value to the App Configuration store and leave **Label** a
63
63
private static IConfigurationRefresher _refresher ;
64
64
```
65
65
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 .
67
67
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
+
68
73
```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
+
69
110
static void Main (string [] args )
70
111
{
71
112
var builder = new ConfigurationBuilder ();
@@ -110,7 +151,33 @@ Add the following key-value to the App Configuration store and leave **Label** a
110
151
111
152
## Build and run the app locally
112
153
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 .
114
181
115
182
If you use the Windows command prompt , run the following command :
116
183
```console
@@ -122,6 +189,13 @@ Add the following key-value to the App Configuration store and leave **Label** a
122
189
$Env : ConnectionString = " <connection-string-of-your-app-configuration-store>"
123
190
```
124
191
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
+
125
199
1 . Restart Visual Studio to allow the change to take effect .
126
200
127
201
1 . Press Ctrl + F5 to build and run the console app .
0 commit comments