Skip to content

Commit e7a10b5

Browse files
Merge pull request #268563 from zhiyuanliang-ms/zhiyuanliang/update-use-keyvault
Azure App Configuration - Update tutorial of using key vault reference
2 parents e0f13cc + 32d1f0c commit e7a10b5

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ You can use the [.NET command-line interface (CLI)](/dotnet/core/tools/) to crea
6262
using Microsoft.Extensions.Configuration.AzureAppConfiguration;
6363
```
6464
65-
4. Use App Configuration by calling the `builder.AddAzureAppConfiguration()` method in the `Program.cs` file.
65+
4. Use App Configuration by calling the `AddAzureAppConfiguration` method in the `Program.cs` file.
6666
6767
```csharp
6868
var builder = new ConfigurationBuilder();

articles/azure-app-configuration/use-key-vault-references-dotnet-core.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ author: maud-lv
66
ms.service: azure-app-configuration
77
ms.devlang: csharp
88
ms.topic: tutorial
9-
ms.date: 02/20/2024
10-
ms.author: malev
9+
ms.date: 03/10/2024
10+
ms.author: zhiyuanliang
1111
ms.custom: devx-track-csharp, mvc, devx-track-dotnet
1212
#Customer intent: I want to update my ASP.NET Core application to reference values stored in Key Vault through App Configuration.
1313
---
@@ -98,21 +98,28 @@ To add a secret to the vault, you need to take just a few additional steps. In t
9898
using Azure.Identity;
9999
```
100100
101-
1. Update the `CreateWebHostBuilder` method to use App Configuration by calling the `config.AddAzureAppConfiguration` method. Include the `ConfigureKeyVault` option, and pass the correct credential to your Key Vault using the `SetCredential` method. If you have multiple Key Vaults, the same credential will be used for all of them. If your Key Vaults require different credentials, you can set them using `Register` or `SetSecretResolver` methods from the [`AzureAppConfigurationKeyVaultOptions`](/dotnet/api/microsoft.extensions.configuration.azureappconfiguration.azureappconfigurationkeyvaultoptions) class.
101+
1. Use App Configuration by calling the `AddAzureAppConfiguration` method. Include the `ConfigureKeyVault` option, and pass the correct credential to your Key Vault using the `SetCredential` method.
102102
103103
```csharp
104104
var builder = WebApplication.CreateBuilder(args);
105105
106+
// Retrieve the connection string
107+
string connectionString = builder.Configuration.GetConnectionString("AppConfig");
108+
109+
// Load configuration from Azure App Configuration
106110
builder.Configuration.AddAzureAppConfiguration(options =>
111+
{
112+
options.Connect(connectionString);
113+
114+
options.ConfigureKeyVault(keyVaultOptions =>
107115
{
108-
options.Connect(
109-
builder.Configuration["ConnectionStrings:AppConfig"])
110-
.ConfigureKeyVault(kv =>
111-
{
112-
kv.SetCredential(new DefaultAzureCredential());
113-
});
116+
keyVaultOptions.SetCredential(new DefaultAzureCredential());
114117
});
118+
});
115119
```
120+
121+
> [!TIP]
122+
> If you have multiple Key Vaults, the same credential will be used for all of them. If your Key Vaults require different credentials, you can set them using `Register` or `SetSecretResolver` methods from the [`AzureAppConfigurationKeyVaultOptions`](/dotnet/api/microsoft.extensions.configuration.azureappconfiguration.azureappconfigurationkeyvaultoptions) class.
116123
117124
1. When you initialized the connection to App Configuration, you set up the connection to Key Vault by calling the `ConfigureKeyVault` method. After the initialization, you can access the values of Key Vault references in the same way you access the values of regular App Configuration keys.
118125

0 commit comments

Comments
 (0)