You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#Customer intent: As an ASP.NET Core developer, I want to learn how to manage all my app settings in one place.
13
13
---
@@ -71,61 +71,115 @@ dotnet new mvc --no-https --output TestAppConfig
71
71
72
72
Access this secret using the .NET Core Configuration API. A colon (`:`) works in the configuration name with the Configuration API on all supported platforms. For more information, see [Configuration keys and values](/aspnet/core/fundamentals/configuration#configuration-keys-and-values).
73
73
74
-
1. In *Program.cs*, add a reference to the .NET Core Configuration API namespace:
74
+
1. Select the correct syntax based on your environment.
75
75
76
-
```csharp
77
-
using Microsoft.Extensions.Configuration;
78
-
```
79
-
80
-
1. Update the `CreateWebHostBuilder` method to use App Configuration by calling the `AddAzureAppConfiguration` method.
81
-
82
-
> [!IMPORTANT]
83
-
> `CreateHostBuilder` replaces `CreateWebHostBuilder` in .NET Core 3.x. Select the correct syntax based on your environment.
84
-
85
-
#### [.NET 5.x](#tab/core5x)
76
+
#### [.NET 6.x](#tab/core6x)
77
+
In *Program.cs*, replace its content with the following code:
86
78
87
79
```csharp
88
-
public static IHostBuilder CreateHostBuilder(string[] args) =>
89
-
Host.CreateDefaultBuilder(args)
90
-
.ConfigureWebHostDefaults(webBuilder =>
91
-
webBuilder.ConfigureAppConfiguration(config =>
92
-
{
93
-
var settings = config.Build();
94
-
var connection = settings.GetConnectionString("AppConfig");
95
-
config.AddAzureAppConfiguration(connection);
96
-
}).UseStartup<Startup>());
80
+
var builder = WebApplication.CreateBuilder(args);
81
+
//Retrieve the Connection String from the secrets manager
82
+
var connectionString = builder.Configuration["AppConfig"];
83
+
84
+
builder.Host.ConfigureAppConfiguration(builder =>
85
+
{
86
+
//Connect to your App Config Store using the connection string
1. In *Program.cs*, add a reference to the .NET Core Configuration API namespace:
117
+
118
+
```csharp
119
+
using Microsoft.Extensions.Configuration;
120
+
```
121
+
122
+
1. Update the `CreateHostBuilder` method to use App Configuration by calling the `AddAzureAppConfiguration` method.
123
+
124
+
```csharp
125
+
public static IHostBuilder CreateHostBuilder(string[] args) =>
126
+
Host.CreateDefaultBuilder(args)
127
+
.ConfigureWebHostDefaults(webBuilder =>
128
+
webBuilder.ConfigureAppConfiguration(config =>
129
+
{
130
+
var settings = config.Build();
131
+
var connection = settings.GetConnectionString("AppConfig");
132
+
config.AddAzureAppConfiguration(connection);
133
+
}).UseStartup<Startup>());
134
+
```
98
135
#### [.NET Core 3.x](#tab/core3x)
99
136
100
-
```csharp
101
-
public static IHostBuilder CreateHostBuilder(string[] args) =>
102
-
Host.CreateDefaultBuilder(args)
103
-
.ConfigureWebHostDefaults(webBuilder =>
104
-
webBuilder.ConfigureAppConfiguration(config =>
137
+
> [!IMPORTANT]
138
+
> `CreateHostBuilder` in .NET 3.x replaces `CreateWebHostBuilder` in .NET Core 2.x.
139
+
140
+
1. In *Program.cs*, add a reference to the .NET Core Configuration API namespace:
141
+
142
+
```csharp
143
+
using Microsoft.Extensions.Configuration;
144
+
```
145
+
1. Update the `CreateHostBuilder` method to use App Configuration by calling the `AddAzureAppConfiguration` method.
146
+
147
+
```csharp
148
+
public static IHostBuilder CreateHostBuilder(string[] args) =>
149
+
Host.CreateDefaultBuilder(args)
150
+
.ConfigureWebHostDefaults(webBuilder =>
151
+
webBuilder.ConfigureAppConfiguration(config =>
152
+
{
153
+
var settings = config.Build();
154
+
var connection = settings.GetConnectionString("AppConfig");
155
+
config.AddAzureAppConfiguration(connection);
156
+
}).UseStartup<Startup>());
157
+
```
158
+
159
+
#### [.NET Core 2.x](#tab/core2x)
160
+
161
+
1. In *Program.cs*, add a reference to the .NET Core Configuration API namespace:
162
+
163
+
```csharp
164
+
using Microsoft.Extensions.Configuration;
165
+
```
166
+
167
+
1. Update the `CreateWebHostBuilder` method to use App Configuration by calling the `AddAzureAppConfiguration` method.
168
+
169
+
```csharp
170
+
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
171
+
WebHost.CreateDefaultBuilder(args)
172
+
.ConfigureAppConfiguration(config =>
105
173
{
106
174
var settings = config.Build();
107
175
var connection = settings.GetConnectionString("AppConfig");
108
176
config.AddAzureAppConfiguration(connection);
109
-
}).UseStartup<Startup>());
110
-
```
111
-
112
-
#### [.NET Core 2.x](#tab/core2x)
113
-
114
-
```csharp
115
-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
116
-
WebHost.CreateDefaultBuilder(args)
117
-
.ConfigureAppConfiguration(config =>
118
-
{
119
-
var settings = config.Build();
120
-
var connection = settings.GetConnectionString("AppConfig");
121
-
config.AddAzureAppConfiguration(connection);
122
-
})
123
-
.UseStartup<Startup>();
124
-
```
125
-
126
-
---
177
+
})
178
+
.UseStartup<Startup>();
179
+
```
180
+
---
127
181
128
-
With the preceding change, the [configuration provider for App Configuration](/dotnet/api/Microsoft.Extensions.Configuration.AzureAppConfiguration) has been registered with the .NET Core Configuration API.
182
+
This code will connect to your App Configuration store using a connection string and load all keys that have the *TestApp* prefix from a previous step. For more information on the configuration provider APIs, reference the [configuration provider for App Configuration docs](/dotnet/api/Microsoft.Extensions.Configuration.AzureAppConfiguration).
129
183
130
184
## Read from the App Configuration store
131
185
@@ -171,7 +225,7 @@ In the preceding code, the App Configuration store's keys are used as follows:
171
225
dotnet run
172
226
```
173
227
174
-
1. If you're working on your local machine, use a browser to navigate to `http://localhost:5000`. This address is the default URL for the locally hosted web app. If you're working in the Azure Cloud Shell, select the **Web Preview** button followed by **Configure**.
228
+
1. If you're working on your local machine, use a browser to navigate to `http://localhost:5000` or as specified in the command output. This address is the default URL for the locally hosted web app. If you're working in the Azure Cloud Shell, select the **Web Preview** button followed by **Configure**.
175
229
176
230

Copy file name to clipboardExpand all lines: includes/azure-app-configuration-add-secret-manager.md
+22Lines changed: 22 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,28 @@
2
2
3
3
A tool called Secret Manager stores sensitive data for development work outside of your project tree. This approach helps prevent the accidental sharing of app secrets within source code. Complete the following steps to enable the use of Secret Manager in the ASP.NET Core project:
4
4
5
+
#### [.NET 6.x](#tab/core6x)
6
+
7
+
Navigate to the project's root directory, and run the following command to enable secrets storage in the project:
8
+
9
+
```dotnetcli
10
+
dotnet user-secrets init
11
+
```
12
+
13
+
A `UserSecretsId` element containing a GUID is added to the *.csproj* file:
Copy file name to clipboardExpand all lines: includes/azure-app-configuration-create.md
+4-3Lines changed: 4 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,12 +7,13 @@ ms.date: 1/31/2020
7
7
---
8
8
9
9
1. To create a new App Configuration store, sign in to the [Azure portal](https://portal.azure.com). In the upper-left corner of the home page, select **Create a resource**. In the **Search the Marketplace** box, enter *App Configuration* and select <kbd>Enter</kbd>.
10
-
11
-

10
+
11
+
:::image type="content" source="media/azure-app-configuration-create/azure-portal-search.png" alt-text="Search for App Configuration":::
12
+
12
13
13
14
1. Select **App Configuration** from the search results, and then select **Create**.
0 commit comments