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
Copy file name to clipboardExpand all lines: articles/azure-app-configuration/quickstart-aspnet-core-app.md
+52-32Lines changed: 52 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,13 +2,13 @@
2
2
title: Quickstart for Azure App Configuration with ASP.NET Core | Microsoft Docs
3
3
description: Quickstart for using Azure App Configuration with ASP.NET Core apps
4
4
services: azure-app-configuration
5
-
author: yegu-ms
5
+
author: jpconnock
6
6
7
7
ms.service: azure-app-configuration
8
8
ms.devlang: csharp
9
9
ms.topic: quickstart
10
-
ms.date: 12/03/2019
11
-
ms.author: yegu
10
+
ms.date: 01/04/2020
11
+
ms.author: jeconnoc
12
12
13
13
#Customer intent: As an ASP.NET Core developer, I want to learn how to manage all my app settings in one place.
14
14
---
@@ -47,18 +47,23 @@ Use the [.NET Core command-line interface (CLI)](https://docs.microsoft.com/dotn
47
47
48
48
1. In the new folder, run the following command to create a new ASP.NET Core MVC web app project:
49
49
50
-
```CLI
51
-
dotnet new mvc --no-https
52
-
```
50
+
```dotnetcli
51
+
dotnet new mvc --no-https
52
+
```
53
53
54
54
## Add Secret Manager
55
55
56
56
To use Secret Manager, add a `UserSecretsId` element to your *.csproj* file.
57
57
58
-
- Open the *.csproj* file. Add a `UserSecretsId` element as shown here. You can use the same GUID, or you can replace this value with your own. Save the file.
58
+
Open the *.csproj* file. Add a `UserSecretsId` element as shown here. You can use the same GUID, or you can replace this value with your own. Save the file.
59
+
60
+
> [!IMPORTANT]
61
+
> `CreateHostBuilder` replaces `CreateWebHostBuilder` in .NET Core 3.0. Select the correct syntax based on your environment.
59
62
60
-
```xml
61
-
<Project Sdk="Microsoft.NET.Sdk.Web">
63
+
#### [.NET Core 2.x](#tab/core2x)
64
+
65
+
```xml
66
+
<ProjectSdk="Microsoft.NET.Sdk.Web">
62
67
63
68
<PropertyGroup>
64
69
<TargetFramework>netcoreapp2.1</TargetFramework>
@@ -70,31 +75,45 @@ To use Secret Manager, add a `UserSecretsId` element to your *.csproj* file.
The Secret Manager tool stores sensitive data for development work outside of your project tree. This approach helps prevent the accidental sharing of app secrets within source code. For more information on Secret Manager, please see [Safe storage of app secrets in development in ASP.NET Core](https://docs.microsoft.com/aspnet/core/security/app-secrets)
77
96
78
97
## Connect to an App Configuration store
79
98
80
99
1. Add a reference to the `Microsoft.Azure.AppConfiguration.AspNetCore` NuGet package by running the following command:
2. Run the following command to restore packages for your project:
104
+
1. Run the following command to restore packages for your project:
86
105
87
-
```CLI
88
-
dotnet restore
106
+
```dotnetcli
107
+
dotnet restore
89
108
```
90
-
3. Add a secret named *ConnectionStrings:AppConfig* to Secret Manager.
109
+
1. Add a secret named *ConnectionStrings:AppConfig* to Secret Manager.
91
110
92
111
This secret contains the connection string to access your App Configuration store. Replace the value in the following command with the connection string for your App Configuration store.
93
112
94
113
This command must be executed in the same directory as the *.csproj* file.
95
114
96
-
```CLI
97
-
dotnet user-secrets set ConnectionStrings:AppConfig <your_connection_string>
115
+
```dotnetcli
116
+
dotnet user-secrets set ConnectionStrings:AppConfig <your_connection_string>
98
117
```
99
118
100
119
> [!IMPORTANT]
@@ -104,18 +123,18 @@ The Secret Manager tool stores sensitive data for development work outside of yo
104
123
105
124
Access this secret using the configuration API. A colon (:) works in the configuration name with the configuration API on all supported platforms. See [Configuration by environment](https://docs.microsoft.com/aspnet/core/fundamentals/configuration/index?tabs=basicconfiguration&view=aspnetcore-2.0).
106
125
107
-
4. Open *Program.cs*, and add a reference to the .NET Core App Configuration provider.
126
+
1. Open *Program.cs*, and add a reference to the .NET Core App Configuration provider.
108
127
109
128
```csharp
110
129
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
111
130
```
112
131
113
-
5. Update the `CreateWebHostBuilder` method to use App Configuration by calling the `config.AddAzureAppConfiguration()` method.
132
+
1. Update the `CreateWebHostBuilder` method to use App Configuration by calling the `config.AddAzureAppConfiguration()` method.
114
133
115
134
> [!IMPORTANT]
116
135
> `CreateHostBuilder` replaces `CreateWebHostBuilder` in .NET Core 3.0. Select the correct syntax based on your environment.
117
136
118
-
### Update `CreateWebHostBuilder` for .NET Core 2.x
137
+
#### [.NET Core 2.x](#tab/core2x)
119
138
120
139
```csharp
121
140
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
@@ -128,8 +147,8 @@ The Secret Manager tool stores sensitive data for development work outside of yo
128
147
.UseStartup<Startup>();
129
148
```
130
149
131
-
### Update `CreateHostBuilder` for .NET Core 3.x
132
-
150
+
#### [.NET Core 3.x](#tab/core3x)
151
+
133
152
```csharp
134
153
public static IHostBuilder CreateHostBuilder(string[] args) =>
135
154
Host.CreateDefaultBuilder(args)
@@ -141,8 +160,9 @@ The Secret Manager tool stores sensitive data for development work outside of yo
141
160
})
142
161
.UseStartup<Startup>());
143
162
```
163
+
---
144
164
145
-
6. Navigate to *<app root>/Views/Home* and open *Index.cshtml*. Replace its content with the following code:
165
+
1. Navigate to *<app root>/Views/Home* and open *Index.cshtml*. Replace its content with the following code:
146
166
147
167
```HTML
148
168
@using Microsoft.Extensions.Configuration
@@ -161,7 +181,7 @@ The Secret Manager tool stores sensitive data for development work outside of yo
7. Navigate to *<app root>/Views/Shared* and open *_Layout.cshtml*. Replace its content with the following code:
184
+
1. Navigate to *<app root>/Views/Shared* and open *_Layout.cshtml*. Replace its content with the following code:
165
185
166
186
```HTML
167
187
<!DOCTYPE html>
@@ -192,17 +212,17 @@ The Secret Manager tool stores sensitive data for development work outside of yo
192
212
193
213
1. To build the app using the .NET Core CLI, navigate to the root directory of your application and run the following command in the command shell:
194
214
195
-
```CLI
196
-
dotnet build
215
+
```dotnetcli
216
+
dotnet build
197
217
```
198
218
199
-
2. After the build successfully completes, run the following command to run the web app locally:
219
+
1. After the build successfully completes, run the following command to run the web app locally:
200
220
201
-
```CLI
202
-
dotnet run
221
+
```dotnetcli
222
+
dotnet run
203
223
```
204
224
205
-
3. If you're working on your local machine, use a browser to navigate to `http://localhost:5000`. This is the default URL for the web app hosted locally.
225
+
1. If you're working on your local machine, use a browser to navigate to `http://localhost:5000`. This is the default URL for the web app hosted locally.
206
226
207
227
If you're working in the Azure Cloud Shell, select the *Web Preview* button followed by *Configure*.
0 commit comments