Skip to content

Commit 526766f

Browse files
Adding .NET 6 support, updating screenshots
1 parent 0141384 commit 526766f

File tree

3 files changed

+92
-9
lines changed

3 files changed

+92
-9
lines changed

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

Lines changed: 70 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,57 @@ dotnet new mvc --no-https --output TestAppConfig
7171
7272
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).
7373
74+
> [!IMPORTANT]
75+
> `CreateHostBuilder` replaces `CreateWebHostBuilder` in .NET Core 3.x. Select the correct syntax based on your environment.
76+
77+
#### [.NET 6.x](#tab/core6x)
78+
79+
1. In *Program.cs*, and replace its content with the following code:
80+
```csharp
81+
var builder = WebApplication.CreateBuilder(args);
82+
builder.Host.ConfigureAppConfiguration(builder =>
83+
{
84+
builder.AddAzureAppConfiguration(options =>
85+
{
86+
//Connect to your App Config Store using a connection string
87+
options.Connect(Environment.GetEnvironmentVariable("AppConfig"))
88+
// Load all keys that start with `TestApp:` and have no label
89+
.Select("TestApp:*");
90+
});
91+
})
92+
.ConfigureServices(services =>
93+
{
94+
// Make Azure App Configuration services available through dependency injection
95+
services.AddAzureAppConfiguration()
96+
.AddControllersWithViews();
97+
});
98+
99+
var app = builder.Build();
100+
101+
// Configure the HTTP request pipeline.
102+
if (!app.Environment.IsDevelopment())
103+
{
104+
app.UseExceptionHandler("/Home/Error");
105+
}
106+
app.UseStaticFiles();
107+
108+
app.UseAzureAppConfiguration();
109+
110+
app.UseRouting();
111+
112+
app.UseAuthorization();
113+
114+
app.MapControllerRoute(
115+
name: "default",
116+
pattern: "{controller=Home}/{action=Index}/{id?}");
117+
118+
app.Run();
119+
```
120+
This will connect to your App Configuration Store using a connection string and load all keys that have the *TestApp* prefix from a previous step.
121+
122+
123+
#### [.NET 5.x](#tab/core5x)
124+
74125
1. In *Program.cs*, add a reference to the .NET Core Configuration API namespace:
75126
76127
```csharp
@@ -79,11 +130,6 @@ dotnet new mvc --no-https --output TestAppConfig
79130
80131
1. Update the `CreateWebHostBuilder` method to use App Configuration by calling the `AddAzureAppConfiguration` method.
81132
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)
86-
87133
```csharp
88134
public static IHostBuilder CreateHostBuilder(string[] args) =>
89135
Host.CreateDefaultBuilder(args)
@@ -95,7 +141,14 @@ dotnet new mvc --no-https --output TestAppConfig
95141
config.AddAzureAppConfiguration(connection);
96142
}).UseStartup<Startup>());
97143
```
98-
#### [.NET Core 3.x](#tab/core3x)
144+
#### [.NET Core 3.x](#tab/core3x)
145+
1. In *Program.cs*, add a reference to the .NET Core Configuration API namespace:
146+
147+
```csharp
148+
using Microsoft.Extensions.Configuration;
149+
```
150+
151+
1. Update the `CreateWebHostBuilder` method to use App Configuration by calling the `AddAzureAppConfiguration` method.
99152
100153
```csharp
101154
public static IHostBuilder CreateHostBuilder(string[] args) =>
@@ -109,7 +162,15 @@ dotnet new mvc --no-https --output TestAppConfig
109162
}).UseStartup<Startup>());
110163
```
111164
112-
#### [.NET Core 2.x](#tab/core2x)
165+
#### [.NET Core 2.x](#tab/core2x)
166+
167+
1. In *Program.cs*, add a reference to the .NET Core Configuration API namespace:
168+
169+
```csharp
170+
using Microsoft.Extensions.Configuration;
171+
```
172+
173+
1. Update the `CreateWebHostBuilder` method to use App Configuration by calling the `AddAzureAppConfiguration` method.
113174
114175
```csharp
115176
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
@@ -123,7 +184,7 @@ dotnet new mvc --no-https --output TestAppConfig
123184
.UseStartup<Startup>();
124185
```
125186
126-
---
187+
---
127188
128189
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.
129190
@@ -171,7 +232,7 @@ In the preceding code, the App Configuration store's keys are used as follows:
171232
dotnet run
172233
```
173234
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**.
235+
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**.
175236
176237
![Locate the Web Preview button](./media/quickstarts/cloud-shell-web-preview.png)
177238

includes/azure-app-configuration-add-secret-manager.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@
22

33
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:
44

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:
14+
15+
```xml
16+
<Project Sdk="Microsoft.NET.Sdk.Web">
17+
18+
<PropertyGroup>
19+
<TargetFramework>net6.0</TargetFramework>
20+
<Nullable>enable</Nullable>
21+
<ImplicitUsings>enable</ImplicitUsings>
22+
<UserSecretsId>8296b5b7-6db3-4ae9-a590-899ac642c0d7</UserSecretsId>
23+
</PropertyGroup>
24+
25+
</Project>
26+
```
527
#### [.NET 5.x](#tab/core5x)
628

729
Navigate to the project's root directory, and run the following command to enable secrets storage in the project:
1000 KB
Loading

0 commit comments

Comments
 (0)