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
+29-19Lines changed: 29 additions & 19 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
---
@@ -43,19 +43,24 @@ In this quickstart, you will use Azure App Configuration to centralize storage a
43
43
44
44
Use the [.NET Core command-line interface (CLI)](https://docs.microsoft.com/dotnet/core/tools/) to create a new ASP.NET Core MVC web app project. The [Azure Cloud Shell](https://shell.azure.com) provides these tools for you. They are also available across the Windows, macOS, and Linux platforms.
45
45
46
-
1. Create a new folder for your project. For this quickstart, name it *TestAppConfig*.
46
+
7. Create a new folder for your project. For this quickstart, name it *TestAppConfig*.
47
47
48
-
1. In the new folder, run the following command to create a new ASP.NET Core MVC web app project:
48
+
8. 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.
62
+
63
+
#### [.NET Core 2.x](#tab/core2x)
59
64
60
65
```xml
61
66
<Project Sdk="Microsoft.NET.Sdk.Web">
@@ -72,22 +77,27 @@ To use Secret Manager, add a `UserSecretsId` element to your *.csproj* file.
72
77
73
78
</Project>
74
79
```
80
+
#### [.NET Core 3.x](#tab/core3x)
81
+
82
+
This includes a bunch of neat stuff for 3x
83
+
84
+
---
75
85
76
86
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
87
78
88
## Connect to an App Configuration store
79
89
80
-
1. Add a reference to the `Microsoft.Azure.AppConfiguration.AspNetCore` NuGet package by running the following command:
90
+
9. 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:
95
+
10. Run the following command to restore packages for your project:
86
96
87
97
```CLI
88
98
dotnet restore
89
99
```
90
-
3. Add a secret named *ConnectionStrings:AppConfig* to Secret Manager.
100
+
11. Add a secret named *ConnectionStrings:AppConfig* to Secret Manager.
91
101
92
102
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
103
@@ -104,13 +114,13 @@ The Secret Manager tool stores sensitive data for development work outside of yo
104
114
105
115
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
116
107
-
4. Open *Program.cs*, and add a reference to the .NET Core App Configuration provider.
117
+
12. Open *Program.cs*, and add a reference to the .NET Core App Configuration provider.
108
118
109
119
```csharp
110
120
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
111
121
```
112
122
113
-
5. Update the `CreateWebHostBuilder` method to use App Configuration by calling the `config.AddAzureAppConfiguration()` method.
123
+
13. Update the `CreateWebHostBuilder` method to use App Configuration by calling the `config.AddAzureAppConfiguration()` method.
114
124
115
125
> [!IMPORTANT]
116
126
> `CreateHostBuilder` replaces `CreateWebHostBuilder` in .NET Core 3.0. Select the correct syntax based on your environment.
@@ -142,7 +152,7 @@ The Secret Manager tool stores sensitive data for development work outside of yo
142
152
.UseStartup<Startup>());
143
153
```
144
154
145
-
6. Navigate to *<app root>/Views/Home* and open *Index.cshtml*. Replace its content with the following code:
155
+
1. Navigate to *<app root>/Views/Home* and open *Index.cshtml*. Replace its content with the following code:
146
156
147
157
```HTML
148
158
@using Microsoft.Extensions.Configuration
@@ -161,7 +171,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:
174
+
14. Navigate to *<app root>/Views/Shared* and open *_Layout.cshtml*. Replace its content with the following code:
165
175
166
176
```HTML
167
177
<!DOCTYPE html>
@@ -190,19 +200,19 @@ The Secret Manager tool stores sensitive data for development work outside of yo
190
200
191
201
## Build and run the app locally
192
202
193
-
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:
203
+
15. 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
204
195
205
```CLI
196
206
dotnet build
197
207
```
198
208
199
-
2. After the build successfully completes, run the following command to run the web app locally:
209
+
16. After the build successfully completes, run the following command to run the web app locally:
200
210
201
211
```CLI
202
212
dotnet run
203
213
```
204
214
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.
215
+
17. 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
216
207
217
If you're working in the Azure Cloud Shell, select the *Web Preview* button followed by *Configure*.
0 commit comments