Skip to content

Commit c89c742

Browse files
authored
Merge pull request #221724 from maud-lv/ml-aac-donetfix
Update code
2 parents 60ddceb + 65199b7 commit c89c742

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed
40.8 KB
Loading

articles/azure-app-configuration/quickstart-aspnet-core-app.md

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ services: azure-app-configuration
55
author: zhenlan
66
ms.service: azure-app-configuration
77
ms.devlang: csharp
8-
ms.custom: devx-track-csharp, contperf-fy21q1, mode-other
8+
ms.custom: devx-track-csharp, contperf-fy21q1, mode-other, engagement-fy23
99
ms.topic: quickstart
10-
ms.date: 9/29/2022
10+
ms.date: 01/04/2023
1111
ms.author: zhenlwa
1212
#Customer intent: As an ASP.NET Core developer, I want to learn how to manage all my app settings in one place.
1313
---
@@ -45,14 +45,17 @@ Use the [.NET Core command-line interface (CLI)](/dotnet/core/tools) to create a
4545
Run the following command to create an ASP.NET Core web app in a new *TestAppConfig* folder:
4646

4747
#### [.NET 6.x](#tab/core6x)
48+
4849
```dotnetcli
4950
dotnet new webapp --output TestAppConfig --framework net6.0
5051
```
5152

5253
#### [.NET Core 3.x](#tab/core3x)
54+
5355
```dotnetcli
5456
dotnet new webapp --output TestAppConfig --framework netcoreapp3.1
5557
```
58+
5659
---
5760

5861
## Connect to the App Configuration store
@@ -75,9 +78,10 @@ dotnet new webapp --output TestAppConfig --framework netcoreapp3.1
7578
7679
Secret Manager stores the secret outside of your project tree, which helps prevent the accidental sharing of secrets within source code. It's used only to test the web app locally. When the app is deployed to Azure like [App Service](../app-service/overview.md), use the *Connection strings*, *Application settings* or environment variables to store the connection string. Alternatively, to avoid connection strings all together, you can [connect to App Configuration using managed identities](./howto-integrate-azure-managed-service-identity.md) or your other [Azure AD identities](./concept-enable-rbac.md).
7780
78-
1. Open *Program.cs*, and add Azure App Configuration as an extra configuration source by calling the `AddAzureAppConfiguration` method.
81+
1. Open *Program.cs* and add Azure App Configuration as an extra configuration source by calling the `AddAzureAppConfiguration` method.
7982
8083
#### [.NET 6.x](#tab/core6x)
84+
8185
```csharp
8286
var builder = WebApplication.CreateBuilder(args);
8387
@@ -90,10 +94,11 @@ dotnet new webapp --output TestAppConfig --framework netcoreapp3.1
9094
// The rest of existing code in program.cs
9195
// ... ...
9296
```
93-
97+
9498
#### [.NET Core 3.x](#tab/core3x)
99+
95100
Update the `CreateHostBuilder` method.
96-
101+
97102
```csharp
98103
public static IHostBuilder CreateHostBuilder(string[] args) =>
99104
Host.CreateDefaultBuilder(args)
@@ -112,6 +117,7 @@ dotnet new webapp --output TestAppConfig --framework netcoreapp3.1
112117
webBuilder.UseStartup<Startup>();
113118
});
114119
```
120+
115121
---
116122
117123
This code will connect to your App Configuration store using a connection string and load *all* key-values that have *no labels*. For more information on the App Configuration provider, see the [App Configuration provider API reference](/dotnet/api/Microsoft.Extensions.Configuration.AzureAppConfiguration).
@@ -120,7 +126,7 @@ dotnet new webapp --output TestAppConfig --framework netcoreapp3.1
120126
121127
In this example, you'll update a web page to display its content using the settings you configured in your App Configuration store.
122128
123-
1. Add a *Settings.cs* file at the root of your project directory. It defines a strongly typed `Settings` class for the configuration you're going to use. Replace the namespace with the name of your project.
129+
1. Add a *Settings.cs* file at the root of your project directory. It defines a strongly typed `Settings` class for the configuration you're going to use. Replace the namespace with the name of your project.
124130
125131
```csharp
126132
namespace TestAppConfig
@@ -138,9 +144,12 @@ In this example, you'll update a web page to display its content using the setti
138144
1. Bind the `TestApp:Settings` section in configuration to the `Settings` object.
139145
140146
#### [.NET 6.x](#tab/core6x)
141-
Update *Program.cs* with the following code.
147+
148+
Update *Program.cs* with the following code and add the `TestAppConfig` namespace at the beginning of the file.
142149
143150
```csharp
151+
using TestAppConfig;
152+
144153
// Existing code in Program.cs
145154
// ... ...
146155
@@ -154,10 +163,11 @@ In this example, you'll update a web page to display its content using the setti
154163
// The rest of existing code in program.cs
155164
// ... ...
156165
```
157-
166+
158167
#### [.NET Core 3.x](#tab/core3x)
168+
159169
Open *Startup.cs* and update the `ConfigureServices` method.
160-
170+
161171
```csharp
162172
public void ConfigureServices(IServiceCollection services)
163173
{
@@ -167,9 +177,10 @@ In this example, you'll update a web page to display its content using the setti
167177
services.Configure<Settings>(Configuration.GetSection("TestApp:Settings"));
168178
}
169179
```
180+
170181
---
171182
172-
1. Open *Index.cshtml.cs* in the *Pages* directory, and update the `IndexModel` class with the following code. Add `using Microsoft.Extensions.Options` namespace at the beginning of the file, if it's not already there.
183+
1. Open *Index.cshtml.cs* in the *Pages* directory, and update the `IndexModel` class with the following code. Add the `using Microsoft.Extensions.Options` namespace at the beginning of the file, if it's not already there.
173184
174185
```csharp
175186
public class IndexModel : PageModel
@@ -223,14 +234,14 @@ In this example, you'll update a web page to display its content using the setti
223234
dotnet run
224235
```
225236
226-
1. Open a browser and navigate to the URL the app is listening on, as specified in the command output. It looks like `https://localhost:5001`.
237+
1. The output of the `dotnet run` command contains two URLs. Open a browser and navigate to either one of these URLs to access your application. For example: `https://localhost:5001`.
227238
228239
If you're working in the Azure Cloud Shell, select the *Web Preview* button followed by *Configure*. When prompted to configure the port for preview, enter *5000*, and select *Open and browse*.
229240
230-
![Locate the Web Preview button](./media/quickstarts/cloud-shell-web-preview.png)
241+
:::image type="content" source="./media/quickstarts/cloud-shell-web-preview.png" alt-text="Screenshot of Azure Cloud Shell. Locate Web Preview.":::
231242
232-
The web page will look like this:
233-
![Launching quickstart app locally](./media/quickstarts/aspnet-core-app-launch-local-before.png)
243+
The web page looks like this:
244+
:::image type="content" source="./media/quickstarts/aspnet-core-app-launch-local-navbar.png" alt-text="Screenshot of the browser.Launching quickstart app locally.":::
234245
235246
## Clean up resources
236247
@@ -248,4 +259,4 @@ In this quickstart, you:
248259
To learn how to configure your ASP.NET Core web app to dynamically refresh configuration settings, continue to the next tutorial.
249260
250261
> [!div class="nextstepaction"]
251-
> [Enable dynamic configuration](./enable-dynamic-configuration-aspnet-core.md)
262+
> [Enable dynamic configuration](./enable-dynamic-configuration-aspnet-core.md)

0 commit comments

Comments
 (0)