Skip to content

Commit 7115c40

Browse files
authored
Merge pull request #199259 from jlichwa/main
Update tutorial for .NET 6.0
2 parents 32d6dcb + aaebd40 commit 7115c40

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

articles/key-vault/general/tutorial-net-create-vault-azure-web-app.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ dotnet add package Azure.Security.KeyVault.Secrets
282282

283283
#### Update the code
284284

285-
Find and open the Startup.cs file in your akvwebapp project.
285+
Find and open the Startup.cs file for .NET 5.0 or earlier, or Program.cs file for .NET 6.0 in your akvwebapp project.
286286

287287
Add these lines to the header:
288288

@@ -292,7 +292,7 @@ using Azure.Security.KeyVault.Secrets;
292292
using Azure.Core;
293293
```
294294

295-
Add the following lines before the `app.UseEndpoints` call, updating the URI to reflect the `vaultUri` of your key vault. This code uses [DefaultAzureCredential()](/dotnet/api/azure.identity.defaultazurecredential) to authenticate to Key Vault, which uses a token from managed identity to authenticate. For more information about authenticating to Key Vault, see the [Developer's Guide](./developers-guide.md#authenticate-to-key-vault-in-code). The code also uses exponential backoff for retries in case Key Vault is being throttled. For more information about Key Vault transaction limits, see [Azure Key Vault throttling guidance](./overview-throttling.md).
295+
Add the following lines before the `app.UseEndpoints` call (.NET 5.0 or earlier) or `app.MapGet` call (.NET 6.0) , updating the URI to reflect the `vaultUri` of your key vault. This code uses [DefaultAzureCredential()](/dotnet/api/azure.identity.defaultazurecredential) to authenticate to Key Vault, which uses a token from managed identity to authenticate. For more information about authenticating to Key Vault, see the [Developer's Guide](./developers-guide.md#authenticate-to-key-vault-in-code). The code also uses exponential backoff for retries in case Key Vault is being throttled. For more information about Key Vault transaction limits, see [Azure Key Vault throttling guidance](./overview-throttling.md).
296296

297297
```csharp
298298
SecretClientOptions options = new SecretClientOptions()
@@ -312,12 +312,23 @@ KeyVaultSecret secret = client.GetSecret("<mySecret>");
312312
string secretValue = secret.Value;
313313
```
314314

315+
##### .NET 5.0 or earlier
316+
315317
Update the line `await context.Response.WriteAsync("Hello World!");` to look like this line:
316318

317319
```csharp
318320
await context.Response.WriteAsync(secretValue);
319321
```
320322

323+
##### .NET 6.0
324+
325+
Update the line `app.MapGet("/", () => "Hello World!");` to look like this line:
326+
327+
```csharp
328+
app.MapGet("/", () => secretValue);
329+
```
330+
331+
321332
Be sure to save your changes before continuing to the next step.
322333

323334
#### Redeploy your web app

0 commit comments

Comments
 (0)