Skip to content

Commit b582403

Browse files
author
Sreekanth Iyer (Ushta Te Consultancy Services)
committed
Resolved Conflict
2 parents 8f5a01d + 1fe2182 commit b582403

File tree

184 files changed

+854
-444
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

184 files changed

+854
-444
lines changed

articles/azure-app-configuration/enable-dynamic-configuration-aspnet-netfx.md

Lines changed: 95 additions & 12 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/20/2023
10+
ms.date: 03/19/2025
1111
ms.author: zhenlwa
1212
#Customer intent: I want to dynamically update my ASP.NET web application (.NET Framework) to use the latest configuration data in App Configuration.
1313
---
@@ -52,15 +52,35 @@ Add the following key-values to the App Configuration store and leave **Label**
5252

5353
## Reload data from App Configuration
5454

55-
1. Right-click your project and select **Manage NuGet Packages**. On the **Browse** tab, search and add the latest version of the following NuGet package to your project.
55+
1. Right-click your project and select **Manage NuGet Packages**. On the **Browse** tab, search and add the latest version of the following NuGet packages to your project.
5656

57-
*Microsoft.Extensions.Configuration.AzureAppConfiguration*
57+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
58+
59+
- *Microsoft.Extensions.Configuration.AzureAppConfiguration*
60+
- *Azure.Identity*
61+
62+
### [Connection string](#tab/connection-string)
63+
64+
- *Microsoft.Extensions.Configuration.AzureAppConfiguration*
65+
---
5866

5967
1. Open *Global.asax.cs* file and add following namespaces.
68+
69+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
70+
71+
```csharp
72+
using Azure.Identity;
73+
using Microsoft.Extensions.Configuration;
74+
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
75+
```
76+
77+
### [Connection string](#tab/connection-string)
78+
6079
```csharp
6180
using Microsoft.Extensions.Configuration;
6281
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
6382
```
83+
---
6484

6585
1. Add the following static member variables to the `Global` class.
6686
```csharp
@@ -69,27 +89,57 @@ Add the following key-values to the App Configuration store and leave **Label**
6989
```
7090

7191
1. Add an `Application_Start` method to the `Global` class. If the method already exists, add the following code to it.
92+
93+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
94+
95+
```csharp
96+
protected void Application_Start(object sender, EventArgs e)
97+
{
98+
ConfigurationBuilder builder = new ConfigurationBuilder();
99+
builder.AddAzureAppConfiguration(options =>
100+
{
101+
string endpoint = Environment.GetEnvironmentVariable("Endpoint");
102+
options.Connect(new Uri(endpoint), new DefaultAzureCredential())
103+
// Load all keys that start with `TestApp:` and have no label.
104+
.Select("TestApp:*")
105+
// Configure to reload configuration if the registered key 'TestApp:Settings:Sentinel' is modified.
106+
.ConfigureRefresh(refresh =>
107+
{
108+
refresh.Register("TestApp:Settings:Sentinel", refreshAll:true)
109+
.SetCacheExpiration(new TimeSpan(0, 5, 0));
110+
});
111+
_configurationRefresher = options.GetRefresher();
112+
});
113+
114+
Configuration = builder.Build();
115+
}
116+
```
117+
118+
### [Connection string](#tab/connection-string)
119+
72120
```csharp
73121
protected void Application_Start(object sender, EventArgs e)
74122
{
75123
ConfigurationBuilder builder = new ConfigurationBuilder();
76124
builder.AddAzureAppConfiguration(options =>
77125
{
78126
options.Connect(Environment.GetEnvironmentVariable("ConnectionString"))
79-
// Load all keys that start with `TestApp:` and have no label.
80-
.Select("TestApp:*")
81-
// Configure to reload configuration if the registered key 'TestApp:Settings:Sentinel' is modified.
82-
.ConfigureRefresh(refresh =>
83-
{
84-
refresh.Register("TestApp:Settings:Sentinel", refreshAll:true)
85-
.SetCacheExpiration(new TimeSpan(0, 5, 0));
86-
});
127+
// Load all keys that start with `TestApp:` and have no label.
128+
.Select("TestApp:*")
129+
// Configure to reload configuration if the registered key 'TestApp:Settings:Sentinel' is modified.
130+
.ConfigureRefresh(refresh =>
131+
{
132+
refresh.Register("TestApp:Settings:Sentinel", refreshAll:true)
133+
.SetCacheExpiration(new TimeSpan(0, 5, 0));
134+
});
87135
_configurationRefresher = options.GetRefresher();
88136
});
89137

90138
Configuration = builder.Build();
91139
}
92140
```
141+
---
142+
93143
The `Application_Start` method is called upon the first request to your web application. It is called only once during the application's life cycle. As such it is a good place to initialize your `IConfiguration` object and load data from App Configuration.
94144

95145
In the `ConfigureRefresh` method, a key within your App Configuration store is registered for change monitoring. The `refreshAll` parameter to the `Register` method indicates that all configuration values should be refreshed if the registered key changes. In this example, the key *TestApp:Settings:Sentinel* is a *sentinel key* that you update after you complete the change of all other keys. When a change is detected, your application refreshes all configuration values. This approach helps to ensure the consistency of configuration in your application compared to monitoring all keys for changes.
@@ -160,7 +210,33 @@ Add the following key-values to the App Configuration store and leave **Label**
160210

161211
## Build and run the application
162212

163-
1. Set an environment variable named **ConnectionString** to the read-only key connection string obtained during your App Configuration store creation.
213+
1. Set an environment variable.
214+
215+
### [Microsoft Entra ID (recommended)](#tab/entra-id)
216+
217+
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.
218+
219+
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
220+
221+
```cmd
222+
setx Endpoint "<endpoint-of-your-app-configuration-store>"
223+
```
224+
225+
If you use PowerShell, run the following command:
226+
227+
```powershell
228+
$Env:Endpoint = "<endpoint-of-your-app-configuration-store>"
229+
```
230+
231+
If you use macOS or Linux, run the following command:
232+
233+
```bash
234+
export Endpoint='<endpoint-of-your-app-configuration-store>'
235+
```
236+
237+
### [Connection string](#tab/connection-string)
238+
239+
Set an environment variable named `ConnectionString` to the read-only key connection string found under **Access settings** of your store in the Azure portal.
164240

165241
If you use the Windows command prompt, run the following command:
166242
```console
@@ -172,6 +248,13 @@ Add the following key-values to the App Configuration store and leave **Label**
172248
$Env:ConnectionString = "<connection-string-of-your-app-configuration-store>"
173249
```
174250

251+
If you use macOS or Linux, run the following command:
252+
253+
```bash
254+
export ConnectionString='<connection-string-of-your-app-configuration-store>'
255+
```
256+
---
257+
175258
1. Restart Visual Studio to allow the change to take effect.
176259

177260
1. Press Ctrl + F5 to build and run the web application.

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

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ms.service: azure-app-configuration
99
ms.devlang: csharp
1010
ms.custom: devx-track-csharp, devx-track-dotnet
1111
ms.topic: tutorial
12-
ms.date: 02/20/2024
12+
ms.date: 03/19/2025
1313
ms.author: malev
1414
#Customer intent: I want to dynamically update my .NET app to use the latest configuration data in App Configuration.
1515
---
@@ -33,24 +33,28 @@ Finish the quickstart [Create a .NET app with App Configuration](./quickstart-do
3333

3434
## Activity-driven configuration refresh
3535

36-
Open *Program.cs* and update the file with the following code.
36+
Open *Program.cs* and update the file with the following code. You can connect to App Configuration using either Microsoft Entra ID (recommended) or a connection string. The following code snippet demonstrates using Microsoft Entra ID.
37+
38+
You use the `DefaultAzureCredential` to authenticate to your App Configuration store. While completing the quickstart listed in the prerequisites, you already [assigned your credential the **App Configuration Data Reader role**](./concept-enable-rbac.md#authentication-with-token-credentials).
3739

3840
```csharp
3941
using Microsoft.Extensions.Configuration;
4042
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
43+
using Azure.Identity;
4144

4245
IConfiguration _configuration = null;
4346
IConfigurationRefresher _refresher = null;
4447

4548
var builder = new ConfigurationBuilder();
4649
builder.AddAzureAppConfiguration(options =>
4750
{
48-
options.Connect(Environment.GetEnvironmentVariable("ConnectionString"))
49-
.ConfigureRefresh(refresh =>
50-
{
51-
refresh.Register("TestApp:Settings:Message")
52-
.SetCacheExpiration(TimeSpan.FromSeconds(10));
53-
});
51+
string endpoint = Environment.GetEnvironmentVariable("Endpoint");
52+
options.Connect(new Uri(endpoint), new DefaultAzureCredential())
53+
.ConfigureRefresh(refresh =>
54+
{
55+
refresh.Register("TestApp:Settings:Message")
56+
.SetCacheExpiration(TimeSpan.FromSeconds(10));
57+
});
5458

5559
_refresher = options.GetRefresher();
5660
});
@@ -114,22 +118,24 @@ In the previous code, you're manually saving an instance of `IConfigurationRefre
114118

115119
## Build and run the app locally
116120

117-
1. Set an environment variable named **ConnectionString**, and set it to the access key to your App Configuration store. If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
121+
1. 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.
118122

119-
```console
120-
setx ConnectionString "<connection-string-of-your-app-configuration-store>"
123+
If you use the Windows command prompt, run the following command and restart the command prompt to allow the change to take effect:
124+
125+
```cmd
126+
setx Endpoint "<endpoint-of-your-app-configuration-store>"
121127
```
122128

123-
If you use Windows PowerShell, run the following command:
129+
If you use PowerShell, run the following command:
124130

125131
```powershell
126-
$Env:ConnectionString = "<connection-string-of-your-app-configuration-store>"
132+
$Env:Endpoint = "<endpoint-of-your-app-configuration-store>"
127133
```
128134

129135
If you use macOS or Linux, run the following command:
130136

131-
```console
132-
export ConnectionString='<connection-string-of-your-app-configuration-store>'
137+
```bash
138+
export Endpoint='<endpoint-of-your-app-configuration-store>'
133139
```
134140

135141
1. Run the following command to build the console app:

0 commit comments

Comments
 (0)