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/key-vault/general/vs-key-vault-add-connected-service.md
+23-93Lines changed: 23 additions & 93 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,121 +7,51 @@ manager: jillfra
7
7
ms.service: key-vault
8
8
ms.custom: "vs-azure, devx-track-csharp"
9
9
ms.topic: how-to
10
-
ms.date: 08/07/2019
10
+
ms.date: 11/14/2022
11
11
ms.author: ghogen
12
12
---
13
13
# Add Key Vault to your web application by using Visual Studio Connected Services
14
14
15
15
In this tutorial, you will learn how to easily add everything you need to start using Azure Key Vault to manage your secrets for web projects in Visual Studio, whether you are using ASP.NET Core or any type of ASP.NET project. By using the Connected Services feature in Visual Studio, you can have Visual Studio automatically add all the NuGet packages and configuration settings you need to connect to Key Vault in Azure.
16
16
17
-
For details on the changes that Connected Services makes in your project to enable Key Vault, see [Key Vault Connected Service - What happened to my ASP.NET 4.7.1 project](#how-your-aspnet-framework-project-is-modified) or [Key Vault Connected Service - What happened to my ASP.NET Core project](#how-your-aspnet-core-project-is-modified).
17
+
For details on the changes that Connected Services makes in your project to enable Key Vault, see [Key Vault Connected Service - What happened to my ASP.NET project](#how-your-aspnet-framework-project-is-modified) or [Key Vault Connected Service - What happened to my ASP.NET Core project](#how-your-aspnet-core-project-is-modified).
18
18
19
19
## Prerequisites
20
20
21
21
-**An Azure subscription**. If you don't have a subscription, sign up for a [free account](https://azure.microsoft.com/pricing/free-trial/).
22
22
-**Visual Studio 2019 version 16.3** or later [Download it now](https://aka.ms/vsdownload?utm_source=mscom&utm_campaign=msdocs).
23
23
24
-
25
24
## Add Key Vault support to your project
26
25
27
-
Before you begin, make sure that you're signed into Visual Studio. Sign in with the same account that you use for your Azure subscription. Then open an ASP.NET 4.7.1 or later, or ASP.NET Core 2.0 web project, and do the follow steps:
26
+
Before you begin, make sure that you're signed into Visual Studio. Sign in with the same account that you use for your Azure subscription. Then open an ASP.NET 4.7.1 or later, or ASP.NET Core web project, and do the following steps. The steps shown are for Visual Studio 2022 version 17.4. The flow might be slightly different for other versions of Visual Studio.
28
27
29
-
1. In **Solution Explorer**, right-click the project that you want to add the Key Vault support to, and choose **Add** > **Connected Service** >**Add**.
28
+
1. In **Solution Explorer**, right-click the project that you want to add the Key Vault support to, and choose **Add** > **Connected Service**. Under**Service Dependencies**, choose the **+** icon.
30
29
The Connected Service page appears with services you can add to your project.
31
30
1. In the menu of available services, choose **Azure Key Vault** and click **Next**.
1. Select the subscription you want to use, and then choose a existing Key Vault and click **Finish**.
36
-
37
-

38
-
39
-
Now, connection to Key Vault is established and you can access your secrets in code. The next steps are different depending on whether you are using ASP.NET 4.7.1 or ASP.NET Core.
40
-
41
-
## Access your secrets in code (ASP.NET Core)
42
-
43
-
1. Open one of the page files, such as *Index.cshtml.cs* and write the following code:
44
-
1. Include a reference to `Microsoft.Extensions.Configuration` by this using directive:
ViewBag.Message="Key vault value = "+ConfigurationManager.AppSettings["<secretNameInYourKeyVault>"];
118
-
}
119
-
```
120
-
1. Runtheapplocallyunderthedebugger, switch to the **About** tab, and verify that the value from the Key Vault is displayed.
34
+
1. Select the subscription you want to use, and then if you already have a Key Vault you want to use, select it and click **Next**.
35
+
36
+

37
+
38
+
1. If you don't have an existing Key Vault, click on **Create new Key Vault**. You'll be asked to provide the resource group, location, and SKU.
39
+
40
+

41
+
42
+
1. In the **Configure Key Vault** screen, you can change the name of the environment variable.
43
+
44
+

45
+
46
+
1. Click **Next** to review a summary of the changes and then **Finish**.
47
+
48
+
Now, connection to Key Vault is established and you can access your secrets in code. If you just created a new key vault, test it by creating a secret that you can reference in code. You can create a secret by using the [Azure portal](../secrets/quick-create-portal.md), [PowerShell](../secrets/quick-create-powershell.md), or the [Azure CLI](../secrets/quick-create-cli.md).
49
+
50
+
See code examples of working with secrets at [Azure Key Vault Secrets client library for .NET - Code examples](../secrets/quick-create-net.md?tabs=azure-cli#code-examples).
121
51
122
52
## Troubleshooting
123
53
124
-
If your Key Vault is running on an different Microsoft account than the one you're logged in to Visual Studio (forexample, theKeyVaultisrunningonyourworkaccount, butVisualStudioisusingyourprivateaccount) you get an error in your Program.cs file, that Visual Studio can't get access to the Key Vault. To fix this issue:
54
+
If your Key Vault is running on a different Microsoft account than the one you're logged in to Visual Studio (for example, the Key Vault is running on your work account, but Visual Studio is using your private account) you get an error in your Program.cs file, that Visual Studio can't get access to the Key Vault. To fix this issue:
125
55
126
56
1. Go to the [Azure portal](https://portal.azure.com) and open your Key Vault.
127
57
@@ -200,4 +130,4 @@ Affects the project file .NET references and `packages.config` (NuGet references
200
130
201
131
If you followed this tutorial, your Key Vault permissions are set up to run with your own Azure subscription, but that might not be desirable for a production scenario. You can create a managed identity to manage Key Vault access for your app. See [How to Authenticate to Key Vault](./authentication.md) and [Assign a Key Vault access policy](./assign-access-policy-portal.md).
0 commit comments