Get started with Key Vault Connected Service in Visual Studio (ASP.NET Core Projects)

[ad_1]


This article provides additional guidance after you’ve added Key Vault to an ASP.NET Core project through the Add Connected Services command in Visual Studio. If you’ve not already added the service to your project, you can do so at any time by following the instructions in Add Key Vault to your web application by using Visual Studio Connected Services.

See What happened to my ASP.NET Core project? for the changes made to your project when adding the connected service.

After you connect

  1. Add a secret in your Key Vault in Azure. To get to the right place in the portal, click on the link for Manage secrets stored in this Key Vault. If you closed the page or the project, you can navigate to it in the Azure portal by choosing All Services, under Security, choose Key Vault, then choose the Key Vault you just created.

    Navigating to the portal

  2. In the Key Vault section for the key vault you created, choose Secrets, then Generate/Import.

    Generate/Import a secret

  3. Enter a secret, such as “MySecret”, and give it any string value as a test, then choose the Create button.

    Create a secret

  4. (optional) Enter another secret, but this time put it into a category by naming it Secrets–MySecret. This syntax specifies a category Secrets that contains a secret MySecret.

  5. In your Visual Studio project, you can now reference these secrets by using the following expressions in code:

       config["MySecret"] // Access a secret without a section
       config["Secrets:MySecret"] // Access a secret in a section
       config.GetSection("Secrets")["MySecret"] // Get the configuration section and access a secret in it.
    

Congratulations, you have now enabled your web app to use Key Vault to access securely stored secrets.

Clean up resources

When no longer needed, delete the resource group. This deletes the Key Vault and related resources. To delete the resource group through the portal:

  1. Enter the name of your resource group in the Search box at the top of the portal. When you see the resource group used in this QuickStart in the search results, select it.
  2. Select Delete resource group.
  3. In the TYPE THE RESOURCE GROUP NAME: box type in the name of the resource group and select Delete.

Learn more about developing with Key Vault in the Key Vault Developer’s Guide




[ad_2]

source_link
https://www.asp.net