{"componentChunkName":"component---src-pages-markdown-remark-fields-slug-js","path":"/engineering/guest-post/using-azure-key-vault-with-an-azure-web-app-in-c-sharp/","result":{"data":{"markdownRemark":{"id":"5ed0008b-aea3-5ad0-a188-c9d9ed140666","excerpt":"Introduction Azure Key Vault is a highly secure, dependable, and simple method to store your keys and secrets in the cloud. This article talks about: Azure Key…","html":"<h2 id=\"introduction\" style=\"position:relative;\"><a href=\"#introduction\" aria-label=\"introduction permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Introduction</h2>\n<p>Azure Key Vault is a highly secure, dependable, and simple method to store your keys and secrets in the cloud. This article talks about:</p>\n<ul>\n<li>Azure Key Vault</li>\n<li>Why it is useful?</li>\n<li>How to set up and configure it?</li>\n<li>How to read a secret value stored inside it in C#?</li>\n</ul>\n<p>Use the following steps to read a secret stored in an Azure Key Vault instance.</p>\n<ol>\n<li>Create a Web App in the Azure Portal</li>\n<li>Enable Managed Service Identity for your Web App</li>\n<li>\n<p>Create and Configure Azure Key Vault</p>\n<ul>\n<li>Create a new Azure Key Vault Instance</li>\n<li>Create an App Secret in Azure key Vault</li>\n<li>Authorize the Web App to Access Key Vault</li>\n</ul>\n</li>\n<li>\n<p>Create a new ASP.NET 5 Core application</p>\n<ul>\n<li>Install NuGet Packages</li>\n<li>Read Azure Key Vault Secrets in .NET Core</li>\n<li>Specify the \"VaultUri\" in AppSettings</li>\n<li>Access Secrets from AzureKeyVault</li>\n<li>Retrieve Secret Value from AzureKeyVault</li>\n<li>Register the Dependencies in the ConfigureServices method</li>\n</ul>\n</li>\n<li>Deploy the Application to Azure</li>\n<li>Execute the Application</li>\n</ol>\n<h2 id=\"prerequisites\" style=\"position:relative;\"><a href=\"#prerequisites\" aria-label=\"prerequisites permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Prerequisites</h2>\n<p>To execute the code examples provided in this article, you should have each of the following:</p>\n<ol>\n<li>Visual Studio 2019 (preferred)</li>\n<li>Azure Account</li>\n</ol>\n<p>If you don't have an Azure account, you can create one for free here: <a href=\"https://portal.azure.com\">Azure Login</a></p>\n<h2 id=\"what-is-azure-key-vault\" style=\"position:relative;\"><a href=\"#what-is-azure-key-vault\" aria-label=\"what is azure key vault permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What is Azure Key Vault?</h2>\n<p>Azure Key Vault is a cloud service that helps you store your application's secrets securely: You can store and manage the keys, passwords, certificates, and other secrets. You can also leverage Azure Key Vault to set parameters shared among multiple applications, including applications running in App Service.</p>\n<p>It enables you to isolate the sensitive and non-sensitive data in your application. For example, you can use application settings to store default parameters or key-value pairs containing some default settings used by the application. On the contrary, you can use Azure Key Vault to store API keys, secret keys, database connection strings, or Client IDs used in your application.</p>\n<h2 id=\"understanding-managed-identity\" style=\"position:relative;\"><a href=\"#understanding-managed-identity\" aria-label=\"understanding managed identity permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Understanding Managed Identity</h2>\n<p>Managed identity is a concept that eliminates the need of having to store credentials once an application has been deployed in the cloud. By using managed identity, you can securely access a variety of Azure services without having to store any credentials like connection strings or passwords. Managed identity may be used to connect to Key Vault from an Azure Function App or an Azure Web App, as well as to connect to Azure Blob Storage from an Azure Web App.</p>\n<p>Managed identities are of the following two types:</p>\n<ul>\n<li><strong>System-assigned</strong> -- this is activated directly on the Azure cloud service. For example, you can create a managed identity for your web app that will be automatically deleted once the web app instance is deleted</li>\n<li><strong>User-assigned</strong> -- this is a stand-alone Azure resource that is created independent of the actual service instance. You can assign this identifier to one or more Azure resources simultaneously. As an example, you can set this identity to both an Azure Web App and an Azure Function at the same time</li>\n</ul>\n<h2 id=\"create-a-web-app-in-the-azure-portal\" style=\"position:relative;\"><a href=\"#create-a-web-app-in-the-azure-portal\" aria-label=\"create a web app in the azure portal permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Create a Web App in the Azure Portal</h2>\n<p>You'll now create an Azure Web App instance with the permissions to access Azure Key Vault. Adhere to the steps given below that would guide you to create a new Azure Web App instance while you’re within the Azure portal:</p>\n<ol>\n<li>In the Azure Portal, click on \"Create a resource\" from the Home screen</li>\n<li>\n<p>Select \"Web App\" from the list</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 64.92307692307692%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAANCAIAAAAmMtkJAAAACXBIWXMAABJ0AAASdAHeZh94AAABV0lEQVQoz5WQy0oEMRBF51PFvSD+hP/gShTdjCtFF4Ljwp0yjjq68AUijtrPpNOppCqvNj3tLGXaSxG4IadupQYrw9na4dfG8ffqwWz96HN3XGxf/dbOuNif8P0JWxRv64bvTfhwWm2eZwNRVRUras5A8OafGmjUQlSgQGmlyHEwkjzYEM9YAj0RGNLGOuMC2eB86MgQmgEAZFmGqL13xvokZ2nBcsalJuMbbYMlIFRIBm1QxtsF3CbHwDzPjTEhtLdKKZBS1sIQLR8bEeu6JiLvffSoFStb0RzuOv4Jx7HjyjqTVvj0UcZkJHLOLYfjjEVRdE9GD+nW6KUSokbnQp9ta80YM9ZGM37nJ9NESMkBre8Bq7k6c53A8WupAGjeazkcx07TrFvP3cvb6eVtBchr5UOvZF2WTAgRzf1jcnbxXINkQroedPvnqM4kefP6HkCjUGR7wD9nsetm279sTQAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Create a new resource in Azure\"\n        title=\"Create a new resource in Azure\"\n        src=\"/static/881710611150de6c542f6656de3b727e/e5715/881710611150de6c542f6656de3b727e.png\"\n        srcset=\"/static/881710611150de6c542f6656de3b727e/a6d36/881710611150de6c542f6656de3b727e.png 650w,\n/static/881710611150de6c542f6656de3b727e/e5715/881710611150de6c542f6656de3b727e.png 768w,\n/static/881710611150de6c542f6656de3b727e/77f8f/881710611150de6c542f6656de3b727e.png 1353w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n</li>\n<li>Specify the name and a region for your web app</li>\n<li>\n<p>Mention the resource group and app service plan for your web app</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 46.15384615384615%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAIAAAC9o5sfAAAACXBIWXMAACHVAAAh1QEEnLSdAAABDklEQVQoz4WRTUsDMRCG9///C8Gjggh69gOKisVDsfSgLQULVXc335NkJps4u0vFQ3FfnjkMJHnnnVQnT/vT58+zhbpb29mbuFl9z9ZqvvPzj1/gZQf3G3u+UJdLxScvXvX1Sl8tRZVAkzel5FIKBResThiGlunKv6qEdgaCD5EoCaVbIZmmFa3UUmljrQPgopRSl2kgHahsoJTz+FJd103TgHOWgXCQZ3XdkSmqv41lGcMeHsBI6R1EHslHD56IJi7HGDkAp7Uh7SW62BFlZJCN87QzYu/wZelhazeNj5QBs3I+TDpzWkLsR0AMzmLso2auxGs55kyDxn08bvXtu4YQMUbes9YGEfOoY1/1A/MGCG8yzXf1AAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Create a Web App\"\n        title=\"Create a Web App\"\n        src=\"/static/5624143e58bd0b77651c034c295db13c/e5715/5624143e58bd0b77651c034c295db13c.png\"\n        srcset=\"/static/5624143e58bd0b77651c034c295db13c/a6d36/5624143e58bd0b77651c034c295db13c.png 650w,\n/static/5624143e58bd0b77651c034c295db13c/e5715/5624143e58bd0b77651c034c295db13c.png 768w,\n/static/5624143e58bd0b77651c034c295db13c/2f6f6/5624143e58bd0b77651c034c295db13c.png 1377w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n</li>\n<li>In the Publish section, there are two choices: \"Code\" and \"Docker Container\". Choose \"Code\"</li>\n<li>Specify \".NET 5\" as the Runtime stack</li>\n<li>Set the Operation system to \"Windows\"</li>\n<li>For the region, specify the one that is closest to you</li>\n<li>You can leave the other options with their default values, and then, click on \"Review + Create\"</li>\n<li>Verify the configuration you've specified. If all is good, click \"Create\"</li>\n</ol>\n<p>Once the Web App has been created successfully, you'll be able to see it on the Home screen of the Azure Portal.</p>\n<h3 id=\"enable-managed-service-identity-for-your-web-app\" style=\"position:relative;\"><a href=\"#enable-managed-service-identity-for-your-web-app\" aria-label=\"enable managed service identity for your web app permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Enable Managed Service Identity for your Web App</h3>\n<p>To enable the system-assigned managed identity for the Azure Web App we just created, follow the steps given below:</p>\n<ol>\n<li>Select \"Identity\" from the left-side menu in the Azure Web App</li>\n<li>Change the \"Status\" toggle pertaining to the System-assigned tab to \"On\"</li>\n<li>Copy the \"Object ID\" that would be available after a few seconds</li>\n</ol>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 44.61538461538462%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAIAAAC9o5sfAAAACXBIWXMAABJ0AAASdAHeZh94AAABJklEQVQoz41QyUoEMRDNv/oByhw8edCf8OxRxAUdBT149Ca4MAwiggw92sz0kj2prD1liyLMoX08XqXyKpVKyOb5fDSebxzN9u8WJ4/14UNz/ETPJvyXpxN+MeUH9+3osty5WWyNy+2rcvd2uXddkOiE4W3ULBgerepS7P4NsqSiZtKlThkoympZNy2lQkqpELoPWhrgGpiy2oIBZ5234JwPhNNWcmaNds7lFGIIgJ4FdGPErAcueqY/yDmTijKw2MsbJV8/aVGr4AHr0BseW+BgUuIlbds8T1/e3mcf84IxBgDYfuCwNkYKgaXeRymN0iakLsTsQ0K6XteJ+1hDGs6D913OxqWKQcNMI/B7PFcelfX6TfaTolLltI1EapvS1wsHh1zHCr7RADXHQl2uAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Enable Managed Service Identity for your Web App\"\n        title=\"Enable Managed Service Identity for your Web App\"\n        src=\"/static/2e9e15c8ac1dfa31c0399b8d95112706/e5715/2e9e15c8ac1dfa31c0399b8d95112706.png\"\n        srcset=\"/static/2e9e15c8ac1dfa31c0399b8d95112706/a6d36/2e9e15c8ac1dfa31c0399b8d95112706.png 650w,\n/static/2e9e15c8ac1dfa31c0399b8d95112706/e5715/2e9e15c8ac1dfa31c0399b8d95112706.png 768w,\n/static/2e9e15c8ac1dfa31c0399b8d95112706/7ebf9/2e9e15c8ac1dfa31c0399b8d95112706.png 1919w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<h2 id=\"create-and-configure-azure-key-vault\" style=\"position:relative;\"><a href=\"#create-and-configure-azure-key-vault\" aria-label=\"create and configure azure key vault permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Create and Configure Azure Key Vault</h2>\n<p>In this section, you’ll examine how to create and configure an Azure Key Vault instance.</p>\n<h3 id=\"create-a-new-azure-key-vault-instance\" style=\"position:relative;\"><a href=\"#create-a-new-azure-key-vault-instance\" aria-label=\"create a new azure key vault instance permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Create a new Azure Key Vault Instance</h3>\n<p>You'll now create an Azure Key Vault in the Azure Portal and then add a secret to it. To create a new Azure Key Vault instance, navigate to the Azure Portal and follow the steps below:</p>\n<ol>\n<li>Select \"Create a resource\" in the Azure Portal menu or the Home page</li>\n<li>Specify \"Key Vault\" in the search box</li>\n<li>When the results are listed, choose \"Key Vault\"</li>\n<li>Click \"Create\"</li>\n</ol>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 60%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAMCAIAAADtbgqsAAAACXBIWXMAABJ0AAASdAHeZh94AAABXUlEQVQoz42Ry0rDQBSG55Hc+wC6FvEdXLn2Mbxg1UVB1GcQoQtRKK0gLlwUEalt2iZpk0xmnEyauWQ8mbGhCEI+TodTmO/8wwnaan/t3Y52b0abrc/Du1mrOz96DI+fwpOn+XkvuujHf+ryOT7tRjvXo+32EAUk99ICc6VLo7SR2ohVFar8r+AaCIgNesuX+wxHKSFKSmNMWZqGIH62zw42oo83TCkl9HsppW5qo+K1Yx6u+gO/805MqcvmuZVsjDImZmLoJznnUkohhNa6kZymJAhCSjBNMSFEWJSS4Ks1YGjd169DlJCZJQgCdwJh6Cr0fR/+RhWL6reAmgtR1MkpOO4SxhAOWyepA2M4YI95ni9XQC/tR6lkEDzPAxlGxHEMJizdAaY7kyTBFmhgJLx8TR6PQZ1MvOl0SqwAac5kGQMylgHMAk29TsQ5h3kuwT77N9A1cDVfg1vq5B/p2aIeapuvLQAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Create a new Key Vault Instance in Azure\"\n        title=\"Create a new Key Vault Instance in Azure\"\n        src=\"/static/9216ad5fd03240b518e4facf1d4e7127/e5715/9216ad5fd03240b518e4facf1d4e7127.png\"\n        srcset=\"/static/9216ad5fd03240b518e4facf1d4e7127/a6d36/9216ad5fd03240b518e4facf1d4e7127.png 650w,\n/static/9216ad5fd03240b518e4facf1d4e7127/e5715/9216ad5fd03240b518e4facf1d4e7127.png 768w,\n/static/9216ad5fd03240b518e4facf1d4e7127/95e59/9216ad5fd03240b518e4facf1d4e7127.png 1460w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<ol start=\"5\">\n<li>In the \"Create key vault\" screen provide the name, subscription, resource group name, and location. Leave the other options to their default values.</li>\n</ol>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 66.61538461538463%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAANCAIAAAAmMtkJAAAACXBIWXMAABJ0AAASdAHeZh94AAABTElEQVQoz5VSzUoDMRjMcwqeFd/D56iiB3spiHfBgxcpFrx5c9dq6dbNZvOfrMk6m7WlZRfBYQhffiaZTEKOp8uT2efZ7eroZnk6+7icl5Onr54X8/J6UQ159VxNX9j5fUEkZ8V6XRQbLUXbtrH9B4jSGjRaW8AY3zTWOmNMCOFvZYwtgYgLoZSSPVIthNj2+i7HziMnVxXNsrc8z98TsizbtXlCX8DLiBhbMsa01k2C3wN6id3g6C0IZJTSnex7i35ktyNGxgJTqqoqTDvQOcSHi0olUXcROtsXaEfE8IMJuEsJtpTymgmjrLfNPp3xw2ck8COV6sKM3aQysBm6dYeMYeQHEHjqvkforoQFGyZXJV8zWZvmkH4oJ1ToTW24TeIQON5VW20caF3j/C+t83EA8vBaTh6Xd4uVlIrzGukgQjwefk2E1z2EAX4AgaPo7/e6GKUAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Specify name, subscription, resource group name, and location for the Key Vault Instance\"\n        title=\"Specify name, subscription, resource group name, and location for the Key Vault Instance\"\n        src=\"/static/9af0907aec14ae465c57c97a6c4ec146/e5715/9af0907aec14ae465c57c97a6c4ec146.png\"\n        srcset=\"/static/9af0907aec14ae465c57c97a6c4ec146/a6d36/9af0907aec14ae465c57c97a6c4ec146.png 650w,\n/static/9af0907aec14ae465c57c97a6c4ec146/e5715/9af0907aec14ae465c57c97a6c4ec146.png 768w,\n/static/9af0907aec14ae465c57c97a6c4ec146/6edca/9af0907aec14ae465c57c97a6c4ec146.png 1351w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<ol start=\"6\">\n<li>Click “Review + Create”</li>\n<li>Review the entered configuration. If all is fine, click \"Create\"</li>\n</ol>\n<h3 id=\"create-an-app-secret-in-azure-key-vault\" style=\"position:relative;\"><a href=\"#create-an-app-secret-in-azure-key-vault\" aria-label=\"create an app secret in azure key vault permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Create an App Secret in Azure Key Vault</h3>\n<p>Now that you've created a Key Value instance, you'll add a secret to it and then make the secret accessible to the Azure Web App we created earlier. Follow the steps below to create a secret:</p>\n<ol>\n<li>Select \"Secrets\" from the \"Settings\" section of the \"Key Vault configuration\" page</li>\n<li>Click \"Generate/Import\" to add a secret</li>\n<li>Select \"Manual\" from the \"Upload options\" dropdown</li>\n<li>Next, mention the name and value of the secret</li>\n<li>Optionally specify the \"Content type\"</li>\n<li>Optionally set the \"activation and expiration date\" options</li>\n<li>Click \"Create\"</li>\n</ol>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 62.92307692307691%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAANCAIAAAAmMtkJAAAACXBIWXMAABJ0AAASdAHeZh94AAABGUlEQVQoz6WRu04DMRBF/Zu0iArxIfT8ACkWJKQU6eiQkKgCRCCB6CgSsrAv7yOxZ8YeL042LCFaoUS5OoWv7dEdj8Vh/+NkEB4PwoPL8elNFDyk58O0N0x692nwKC9G+QbBKL96Ks7ukqP+ROQyi5IkTjNjud5RggwhArP1hp2z1rpW9Qpu3Jrc4nItEFEpXS+P2HIhC9Jo0PwC5HeYO/oSoDURNcanfk6TKEzjL9kyr1DNyJquYp9clqVSyhuyXIKtkCu0a3CJbNh1JYP2xQC4TLZItPG8/wYGAG3bivj6rZCVH8FWkxf1HhLstm9zv2T3V+JlOptkuvn3nZNvX6Pn95gtmR8RklboAb2gWXvUHHJZyGyFX38DgoDxSx+YEVEAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Create a new Secret\"\n        title=\"Create a new Secret\"\n        src=\"/static/f0c25e31cb9de4940c50cf37bf04e26d/e5715/f0c25e31cb9de4940c50cf37bf04e26d.png\"\n        srcset=\"/static/f0c25e31cb9de4940c50cf37bf04e26d/a6d36/f0c25e31cb9de4940c50cf37bf04e26d.png 650w,\n/static/f0c25e31cb9de4940c50cf37bf04e26d/e5715/f0c25e31cb9de4940c50cf37bf04e26d.png 768w,\n/static/f0c25e31cb9de4940c50cf37bf04e26d/07a9c/f0c25e31cb9de4940c50cf37bf04e26d.png 1440w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<h3 id=\"authorize-the-web-app-to-access-your-key-vault\" style=\"position:relative;\"><a href=\"#authorize-the-web-app-to-access-your-key-vault\" aria-label=\"authorize the web app to access your key vault permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Authorize the Web App to access Your Key Vault</h3>\n<p>To provide access to the secret you created, follow the steps below:</p>\n<ol>\n<li>Select \"Access policies\" from the \"Key Vault\" screen</li>\n<li>Click \"Add Access Policy\"</li>\n<li>Provide the \"Get\" and \"List\" permissions</li>\n<li>In the “Select a Principal” option, specify the value for the \"Object ID\" you\ncopied earlier for the Azure Web App</li>\n<li>Paste, search and then select it from the list</li>\n<li>Click \"Add\"</li>\n<li>Click \"Save\" to persist the changes and complete the process</li>\n</ol>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 60.30769230769231%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAMCAIAAADtbgqsAAAACXBIWXMAABJ0AAASdAHeZh94AAABD0lEQVQoz5WQPU/DMBCG8+tYkRiZmJH6cxBLqRAslVhg4BcgBqiYGRhQi0ILSdM4duyzzx+cUyJFCBL66tXJp/Oj+0j2LxaH0/To6n1vMh/dpJOH7OT+87Tx+HF9Nit+eDwrzp+K4+v04HKebEqWrrK3VZ5tSh+CC8G3dj7a/maqkhINSgpuQFnUYUclACCE0FobYyxiLYShZ8yiNMAwbK2lxGhkBUON1lgD2Nj0w6pijJpQUiuz/Mh5xaWU3sW9tvFPuJZQlBXouPBiLV+WJRHYDBJh3wvfvYrbZ+YcnTnQ5qyquuUBWFsP9vsHInLOu8AA3E0IZoxR3A6yG0xny/OcmiulXKv/wt1WvlUP/AUpNLW8EED0XAAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Add Access Policy for the Key Vault\"\n        title=\"Add Access Policy for the Key Vault\"\n        src=\"/static/20064fe32ee34d74ab431409b7b3fcf6/e5715/20064fe32ee34d74ab431409b7b3fcf6.png\"\n        srcset=\"/static/20064fe32ee34d74ab431409b7b3fcf6/a6d36/20064fe32ee34d74ab431409b7b3fcf6.png 650w,\n/static/20064fe32ee34d74ab431409b7b3fcf6/e5715/20064fe32ee34d74ab431409b7b3fcf6.png 768w,\n/static/20064fe32ee34d74ab431409b7b3fcf6/bb5d0/20064fe32ee34d74ab431409b7b3fcf6.png 1453w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<h2 id=\"create-a-new-aspnet-5-core-application\" style=\"position:relative;\"><a href=\"#create-a-new-aspnet-5-core-application\" aria-label=\"create a new aspnet 5 core application permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Create a New ASP.NET 5 Core application</h2>\n<p>First of all, you'll create an ASP.NET Core 5 web application. The project type comes bundled with all the template files to create a web application, even before you add something. Follow the steps given below to create a new ASP.NET Core Web application within the Visual Studio 2019 IDE.</p>\n<ol>\n<li>Launch Visual Studio 2019</li>\n<li>In the start window, choose \"Create a new project\"</li>\n<li>In the \"Add a new project\" window, choose \"ASP.NET Core Web API\" from the list of the project templates</li>\n</ol>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 66.15384615384615%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAANCAIAAAAmMtkJAAAACXBIWXMAABJ0AAASdAHeZh94AAABh0lEQVQoz41S2W7bMBDU//9gC9RtAsSRrSXFY3mLlJEh2ThonjpYLShyZ+9FKSaSQioSUkq1bdKyi6mEkLyPU0LMISYfIiTGDPHjdcFH211KQbQJQbfbGmN4PM5SSuxIOBwDtR44Q9da28DiXNwVb6RJmvu2h1hTainXnJO2ZnBwk2JK53ni7L3HL5g4L8zh8ip//BI/L+Ltlq73vFI03IzRl98XVEJEzjk/EEKYug50MrNhtvAOd5DjKNA5F22sMcZaO6MBM5EnFufjvu/DPVvL6AgskCFof15elVJ49Z/4Htn1frLSGo7nVc6565LBBxP6Gflp80lm7w3Gw25g5oZ+wP1Gd9HnJ/2/gNloO2p2QSuNCDCajnthqDkVvbNFKdb24Q58q7yPio3XRjPzvO1eW02hrG90fb8C67r2BRqYhXxFRp+01sgHw5/kmXkpeeb5LDuOdiK3RxuRsWjt7OOZhIH6V9d6fqF1ae1xNrL5RYR81AW73XcVOxkT9vl/hLR/l+x8+gCCUOlhSpe4XAAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Create a new project in Visual Studio\"\n        title=\"Create a new project in Visual Studio\"\n        src=\"/static/68f5590f4a272da6dca010ff6f0bcfde/e5715/68f5590f4a272da6dca010ff6f0bcfde.png\"\n        srcset=\"/static/68f5590f4a272da6dca010ff6f0bcfde/a6d36/68f5590f4a272da6dca010ff6f0bcfde.png 650w,\n/static/68f5590f4a272da6dca010ff6f0bcfde/e5715/68f5590f4a272da6dca010ff6f0bcfde.png 768w,\n/static/68f5590f4a272da6dca010ff6f0bcfde/53ac9/68f5590f4a272da6dca010ff6f0bcfde.png 1287w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<ol start=\"4\">\n<li>Select \"C#\" as the programming language from the \"Language\" list</li>\n<li>Click \"Next\"</li>\n<li>In the \"Configure your new project\" screen, enter the name and location of the new project</li>\n<li>Then, choose \"Next\"</li>\n<li>In the \"Additional information\" window, ensure that .NET 5.0 (current) is selected as the framework version</li>\n</ol>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 66.15384615384615%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAANCAIAAAAmMtkJAAAACXBIWXMAABJ0AAASdAHeZh94AAAA8klEQVQoz5WR226EMAxE+f+/RBQKIRsn4Dixw0o16UXtstB2NA+WwvEYu2EWAO+c8z6oag2IWEoR2f1VfLdSOXMjIi9d17Zt13XDMIzj1Pe99mJ9F+GqUlsc1eg3wYMPezAR3asUyykpljmrROQUni2MxnnMMQlGXiMjyV7Tbkpcynmymd00g18zKXPwL7CDBQK6EGvmo69g/R0AN5k5IN237amvkie7vN6iDWkGerABuoVYTta9n0r3bKwzFtySiDj+9PXYsn2Od6Yj9n675uyGT6VtPpLu2/9gnSBG8n7xC1mPLHVhf1dKCTFiTKteleUNMgfzej8PmXgAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Specify additional information for the new ASP.NET Core 5 project\"\n        title=\"Specify additional information for the new ASP.NET Core 5 project\"\n        src=\"/static/307b2784a56ac53e9fac3730a568c92d/e5715/307b2784a56ac53e9fac3730a568c92d.png\"\n        srcset=\"/static/307b2784a56ac53e9fac3730a568c92d/a6d36/307b2784a56ac53e9fac3730a568c92d.png 650w,\n/static/307b2784a56ac53e9fac3730a568c92d/e5715/307b2784a56ac53e9fac3730a568c92d.png 768w,\n/static/307b2784a56ac53e9fac3730a568c92d/1320e/307b2784a56ac53e9fac3730a568c92d.png 1292w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<ol>\n<li>Since you'll not be using authentication, HTTPS or Docker, or OpenAPI, ensure that all these checkboxes are disabled</li>\n<li>Click \"Create\" to complete the process</li>\n</ol>\n<p>A new ASP.NET 5 Core application will be created in Visual Studio.</p>\n<h3 id=\"install-the-nuget-packages\" style=\"position:relative;\"><a href=\"#install-the-nuget-packages\" aria-label=\"install the nuget packages permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Install the NuGet Packages</h3>\n<p>To work with AzureKeyVault, you must install <code>Microsoft.Extensions.Azure</code> and <code>Azure.Security.KeyVault.Secrets</code> packages. While you can use the former for injecting dependencies for accessing Azure services, you can use the latter to access secrets via a SecretClient instance.</p>\n<p>You may install these packages in one of two ways: Either via the NuGet Package Manager integrated into the Visual Studio 2019 IDE or by running the following command(s) in the Package Manager Console:</p>\n<p><code>Install-Package Microsoft.Extensions.Azure</code></p>\n<p><code>Install-Package Azure.Security.KeyVault.Secrets</code></p>\n<h3 id=\"read-azure-key-vault-secrets-in-net-core\" style=\"position:relative;\"><a href=\"#read-azure-key-vault-secrets-in-net-core\" aria-label=\"read azure key vault secrets in net core permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Read Azure Key Vault Secrets in .NET Core</h3>\n<p>In this section, you’ll examine how to read secrets from AzureKeyVault.</p>\n<h4 id=\"specify-the-vault-uri-in-appsettings\" style=\"position:relative;\"><a href=\"#specify-the-vault-uri-in-appsettings\" aria-label=\"specify the vault uri in appsettings permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Specify the Vault Uri in AppSettings</h4>\n<p>Create a section named \"KeyVault\" in the <code>appsettings.json</code> file and specify a key named \"VaultUri\" in there as shown below:</p>\n<p><code>\"KeyVault\": {</code></p>\n<p><code>\"VaultUri\": \"https://applicationsecretsdemo.vault.azure.net/\"</code></p>\n<p><code>}</code></p>\n<h4 id=\"access-secrets-from-azurekeyvault\" style=\"position:relative;\"><a href=\"#access-secrets-from-azurekeyvault\" aria-label=\"access secrets from azurekeyvault permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Access Secrets from AzureKeyVault</h4>\n<p>To access the secrets stored in the AzureKeyVault, you can take advantage of SecretClient pertaining to the  <code>Azure.Security.KeyVault.Secrets</code> namespace. Create an interface named \"IKeyVaultManager\" with the following code in there:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"c#\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">public</span><span class=\"mtk1\"> </span><span class=\"mtk4\">interface</span><span class=\"mtk1\"> </span><span class=\"mtk10\">IKeyVaultManager</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">public </span><span class=\"mtk10\">Task</span><span class=\"mtk1\">&lt;</span><span class=\"mtk4\">string</span><span class=\"mtk1\">&gt; </span><span class=\"mtk11\">GetSecret</span><span class=\"mtk1\">(</span><span class=\"mtk4\">string</span><span class=\"mtk1\"> </span><span class=\"mtk12\">secretName</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span></code></pre>\n<p>Create a class named \"KeyVaultManager\" that extends the \"IKeyVaultManager\" interface and implements the <code>GetSecret</code> method as follows:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"c#\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">public</span><span class=\"mtk1\"> </span><span class=\"mtk4\">class</span><span class=\"mtk1\"> </span><span class=\"mtk10\">KeyVaultManager</span><span class=\"mtk1\">:</span><span class=\"mtk10\">IKeyVaultManager</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">private</span><span class=\"mtk1\"> </span><span class=\"mtk4\">readonly</span><span class=\"mtk1\"> </span><span class=\"mtk10\">SecretClient</span><span class=\"mtk1\"> </span><span class=\"mtk12\">_secretClient</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">public</span><span class=\"mtk1\"> </span><span class=\"mtk11\">KeyVaultManager</span><span class=\"mtk1\">(</span><span class=\"mtk10\">SecretClient</span><span class=\"mtk1\"> </span><span class=\"mtk12\">secretClient</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\"> </span><span class=\"mtk12\">_secretClient</span><span class=\"mtk1\"> = </span><span class=\"mtk12\">secretClient</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">public</span><span class=\"mtk1\"> </span><span class=\"mtk4\">async</span><span class=\"mtk1\"> </span><span class=\"mtk10\">Task</span><span class=\"mtk1\">&lt;</span><span class=\"mtk4\">string</span><span class=\"mtk1\">&gt; </span><span class=\"mtk11\">GetSecret</span><span class=\"mtk1\">(</span><span class=\"mtk4\">string</span><span class=\"mtk1\"> </span><span class=\"mtk12\">secretName</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">try</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk10\">KeyVaultSecret</span><span class=\"mtk1\"> </span><span class=\"mtk12\">keyValueSecret</span><span class=\"mtk1\"> = </span><span class=\"mtk4\">await</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">_secretClient</span><span class=\"mtk1\">.</span><span class=\"mtk11\">GetSecretAsync</span><span class=\"mtk1\">(</span><span class=\"mtk12\">secretName</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">return</span><span class=\"mtk1\"> </span><span class=\"mtk12\">keyValueSecret</span><span class=\"mtk1\">.</span><span class=\"mtk12\">Value</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">catch</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">throw</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span></code></pre>\n<p>The \"KeyVaultManager\" class leverages the \"SecretClient\" class to retrieve secrets stored inside the AzureKeyVault.</p>\n<h4 id=\"the-keyvaluecontroller-class\" style=\"position:relative;\"><a href=\"#the-keyvaluecontroller-class\" aria-label=\"the keyvaluecontroller class permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>The KeyValueController Class</h4>\n<p>The \"KeyValueController\" takes advantages of the \"KeyValueManager\" class to read the secret value for a given secret name and returns the value stored in there.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"c#\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">public</span><span class=\"mtk1\"> </span><span class=\"mtk4\">class</span><span class=\"mtk1\"> </span><span class=\"mtk10\">KeyVaultController</span><span class=\"mtk1\"> : </span><span class=\"mtk10\">ControllerBase</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">private</span><span class=\"mtk1\"> </span><span class=\"mtk4\">readonly</span><span class=\"mtk1\"> </span><span class=\"mtk10\">IKeyVaultManager</span><span class=\"mtk1\"> </span><span class=\"mtk12\">_secretManager</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">public</span><span class=\"mtk1\"> </span><span class=\"mtk11\">KeyVaultController</span><span class=\"mtk1\">(</span><span class=\"mtk10\">IKeyVaultManager</span><span class=\"mtk1\"> </span><span class=\"mtk12\">secretManager</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">_secretManager</span><span class=\"mtk1\"> = </span><span class=\"mtk12\">secretManager</span><span class=\"mtk1\">;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">[</span><span class=\"mtk10\">HttpGet</span><span class=\"mtk1\">]</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">public</span><span class=\"mtk1\"> </span><span class=\"mtk4\">async</span><span class=\"mtk1\"> </span><span class=\"mtk10\">Task</span><span class=\"mtk1\">&lt;</span><span class=\"mtk10\">IActionResult</span><span class=\"mtk1\">&gt; </span><span class=\"mtk11\">Get</span><span class=\"mtk1\">([</span><span class=\"mtk10\">FromQuery</span><span class=\"mtk1\">] </span><span class=\"mtk4\">string</span><span class=\"mtk1\"> </span><span class=\"mtk12\">secretName</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">try</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">if</span><span class=\"mtk1\"> (</span><span class=\"mtk12\">string</span><span class=\"mtk1\">.</span><span class=\"mtk11\">IsNullOrEmpty</span><span class=\"mtk1\">(</span><span class=\"mtk12\">secretName</span><span class=\"mtk1\">))</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">return</span><span class=\"mtk1\"> </span><span class=\"mtk11\">BadRequest</span><span class=\"mtk1\">();</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">string</span><span class=\"mtk1\"> </span><span class=\"mtk12\">secretValue</span><span class=\"mtk1\"> = </span><span class=\"mtk4\">await</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">_secretManager</span><span class=\"mtk1\">.</span><span class=\"mtk11\">GetSecret</span><span class=\"mtk1\">(</span><span class=\"mtk12\">secretName</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">if</span><span class=\"mtk1\"> (!</span><span class=\"mtk12\">string</span><span class=\"mtk1\">.</span><span class=\"mtk11\">IsNullOrEmpty</span><span class=\"mtk1\">(</span><span class=\"mtk12\">secretValue</span><span class=\"mtk1\">))</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">return</span><span class=\"mtk1\"> </span><span class=\"mtk11\">Ok</span><span class=\"mtk1\">(</span><span class=\"mtk12\">secretValue</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">else</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">return</span><span class=\"mtk1\"> </span><span class=\"mtk11\">NotFound</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;Secret key not found.&quot;</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">catch</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">return</span><span class=\"mtk1\"> </span><span class=\"mtk11\">BadRequest</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;Error: Unable to read secret&quot;</span><span class=\"mtk1\">);</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span></code></pre>\n<h4 id=\"register-the-dependencies-in-the-configureservices-method\" style=\"position:relative;\"><a href=\"#register-the-dependencies-in-the-configureservices-method\" aria-label=\"register the dependencies in the configureservices method permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Register the Dependencies in the ConfigureServices Method</h4>\n<p>You should specify the necessary code for dependency injection to work in the \"ConfigureServices\" method of the \"Startup\" class as shown in the code snippet given below:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"c#\" data-index=\"3\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk4\">public</span><span class=\"mtk1\"> </span><span class=\"mtk4\">void</span><span class=\"mtk1\"> </span><span class=\"mtk11\">ConfigureServices</span><span class=\"mtk1\">(</span><span class=\"mtk10\">IServiceCollection</span><span class=\"mtk1\"> </span><span class=\"mtk12\">services</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">services</span><span class=\"mtk1\">.</span><span class=\"mtk11\">AddAzureClients</span><span class=\"mtk1\">(</span><span class=\"mtk12\">azureClientFactoryBuilder</span><span class=\"mtk1\"> =&gt;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">{</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">azureClientFactoryBuilder</span><span class=\"mtk1\">.</span><span class=\"mtk11\">AddSecretClient</span><span class=\"mtk1\">(</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">Configuration</span><span class=\"mtk1\">.</span><span class=\"mtk11\">GetSection</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;KeyVault&quot;</span><span class=\"mtk1\">));</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">});</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">services</span><span class=\"mtk1\">.</span><span class=\"mtk11\">AddSingleton</span><span class=\"mtk1\">&lt;</span><span class=\"mtk10\">IKeyVaultManager</span><span class=\"mtk1\">,</span><span class=\"mtk10\">KeyVaultManager</span><span class=\"mtk1\">&gt;();</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk12\">services</span><span class=\"mtk1\">.</span><span class=\"mtk11\">AddControllersWithViews</span><span class=\"mtk1\">();</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">}</span></span></code></pre>\n<h2 id=\"deploy-the-application-to-azure\" style=\"position:relative;\"><a href=\"#deploy-the-application-to-azure\" aria-label=\"deploy the application to azure permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Deploy the Application to Azure</h2>\n<p>To deploy the application, follow the steps below:</p>\n<ol>\n<li>Right-click on the project in the \"Solution Explorer Window\"</li>\n<li>Select \"Publish\"</li>\n<li>Select \"Azure\" as the target from the \"Publish\" window as shown below:</li>\n</ol>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 67.38461538461537%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAANCAIAAAAmMtkJAAAACXBIWXMAABJ0AAASdAHeZh94AAABZklEQVQoz4VSiW6DMAzl/79vqrSVqcdK00JISHPYCQ7MlHbrJfXpYVkhTz5eCue8d7ZPMcVo7cl7zylivAAjImaicRgeyCh24rTZKVE7D6gtyM5z9ocA4EPoe8p5eCSLj41rNRibAkTugkuO42MZelIS5QBYIOA4ZOoTANZ1o5S21llrc87jHYZ7jjxa4T1wVylNlUUNB0lCpsXaf3w25caVW7/cOOaqwvU+rfeR46qKWxG5y8IHIJrEGNN5CyMkKoVdbY9f5c/yuzrU5tjYVgFPN1N16EIO4UYcY5r7I+q7rjZGO2/ZCIQwEXltkaebIk03AV+JcyaraymlOZmU+tmynt26x2sx21JLLfb7qqrY9tmz4Yo3Yt6zEIIrt23L4hACL58T5xznb8T8IqRF2TSsD1c8OXcvZt/YfgadcU74u3A+ZFMvf+l/2z2jM+zHSekzlbllO8WurNRi02ptmkbtqqPS5heYZfBnZTDJMgAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Deploy the application to Azure\"\n        title=\"Deploy the application to Azure\"\n        src=\"/static/8e627ca65b5d868ab7fca443032bc43c/e5715/8e627ca65b5d868ab7fca443032bc43c.png\"\n        srcset=\"/static/8e627ca65b5d868ab7fca443032bc43c/a6d36/8e627ca65b5d868ab7fca443032bc43c.png 650w,\n/static/8e627ca65b5d868ab7fca443032bc43c/e5715/8e627ca65b5d868ab7fca443032bc43c.png 768w,\n/static/8e627ca65b5d868ab7fca443032bc43c/91608/8e627ca65b5d868ab7fca443032bc43c.png 1251w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<ol start=\"4\">\n<li>Select \"Azure App Service (Windows)\" as the specific target as shown below:</li>\n</ol>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 70.3076923076923%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAOCAIAAACgpqunAAAACXBIWXMAABJ0AAASdAHeZh94AAABUUlEQVQoz8WS2W6DMBBF+f//4qFNFbV5aJY2CREQIF7wjgHbdCBR2ipqlT716mhkX3Rlj5lI6cbarm37vvdA953R6dwt4EMwklKXZcEYCyF476EMQ5gYwmi58/pW8DHSplFSNEYbrRjjhDBCGVRMGMIU4bqxvfND7y5cLwUHQdhiqqR2XT+8pTxelA/zNH5K4tk+niWLdf2yqp+XdLGqzyx3ZnOwrzuLWRcJ1SaZ2B5Yhbtdqd/SOjlUm22+fs/ygsHBiGhMDQKIocxy5YTyXPrGugieampgbIMKnZ+w4DVGCGNkjGoaA1ioRkFfzrlrz3DvS9hP4T2x85TjqkizHKS1Hn7WZ/i6PytMgr8XQvhDeLhb/xzu+q9Dc394nDAhTdu21o4YY2/RupFSSWUJN0JdTCEU+NHpRCnlvwATmmfFPqePG7Q9spoyjFmaHquKfADGUysIFUznAgAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Specify the Azure service to host your application\"\n        title=\"Specify the Azure service to host your application\"\n        src=\"/static/f80e91e7daf51e89558a3e863ce72e2a/e5715/f80e91e7daf51e89558a3e863ce72e2a.png\"\n        srcset=\"/static/f80e91e7daf51e89558a3e863ce72e2a/a6d36/f80e91e7daf51e89558a3e863ce72e2a.png 650w,\n/static/f80e91e7daf51e89558a3e863ce72e2a/e5715/f80e91e7daf51e89558a3e863ce72e2a.png 768w,\n/static/f80e91e7daf51e89558a3e863ce72e2a/6bfd0/f80e91e7daf51e89558a3e863ce72e2a.png 1011w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<ol start=\"5\">\n<li>Specify, or associate, the \"App Service instance\" with your application</li>\n</ol>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 70.3076923076923%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAOCAIAAACgpqunAAAACXBIWXMAABJ0AAASdAHeZh94AAABhklEQVQoz4VSy27bMBDk/39Ez+0v5JhLe2p8awOjQeKItiVBFMX3Yyl1RMOJHeQxGCyIFWe1yx1mrHc+hBAzlZwraWXK9IbBKONwNzufcN0Yx7Qxe86llMuylAqqmOd5ecV63mxu/vy93T4ctw87fhQhJmatN8ZYa7XWSukaJ8SU0nINX+ackc4nIMPQcAjuVLvrxdPuwA+9NsEHMj7bCwY0HMhXOg85MW1jc5D8ME2ahlFJZZXxxkXM9gkxdiZiysTHZuKt70baH/uuH4xFN/SFOFQxZniZKsZElFfmVCh/goCr+VpstHpu+CPvRu2VSzG9r8QulMWK46sYL5aD+/2v/faz/bGR3+9Er0LJCf94F3TZNva6roEK7IKJYIP0cdt1Y9fieG6UTt8/BiwJIcPcFw+Gna/AgS5QyoxQD2WZqwurF5nWLq4+Wam1FUIOwzhNCqXPjHCh9ygcrU94S7jAWocMazshxHSmGkddqV6SfS92uz3iKOTTUf6677fN0Dzzth3+A49IKcX4o/tqAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Publish your application\"\n        title=\"Publish your application\"\n        src=\"/static/89177ae5689c32f917b8d609f07f8ecc/e5715/89177ae5689c32f917b8d609f07f8ecc.png\"\n        srcset=\"/static/89177ae5689c32f917b8d609f07f8ecc/a6d36/89177ae5689c32f917b8d609f07f8ecc.png 650w,\n/static/89177ae5689c32f917b8d609f07f8ecc/e5715/89177ae5689c32f917b8d609f07f8ecc.png 768w,\n/static/89177ae5689c32f917b8d609f07f8ecc/d6a46/89177ae5689c32f917b8d609f07f8ecc.png 1008w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<ol start=\"6\">\n<li>Click \"Finish\"</li>\n</ol>\n<h2 id=\"execute-the-application\" style=\"position:relative;\"><a href=\"#execute-the-application\" aria-label=\"execute the application permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Execute the Application</h2>\n<p>Lastly, you can use Postman to send a <code>Http Get</code> request to the endpoint to retrieve the stored secret as shown below:</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 43.84615384615385%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAIAAAC9o5sfAAAACXBIWXMAABJ0AAASdQHHfS45AAAA/ElEQVQoz4VSO3bEIAzk0DlN7pEyB0iRetuUW3j5Yz4SkAE2+9ikyDyePQhrNBIWTt6ivnGOxNzqQGvrXfsf4Mh7TyWD9s7CWKuNVVprpdXEoEpJKWOMpRTakHO2Rl9VfL+4zy8vfICWXwnaaGPMyl8Ez/M8oZImQBulyzW/vJ2vH0l4ayAJk8RUp9+1BZj5YXi1szVQeyVxHAe+nvu+jlHBWtueEUJA/cWhAwuICHS1VB9AQcjtESgiuFW+E3EXmxN+MrahcqXRBHMdi7gVHikCU3HBWwenFk5ySiWlX9dDhTLuZ65CJVGVLoWYBUYdfHA/QD5G1//D+he+AWHuDW/cX8wPAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Execute the application\"\n        title=\"Execute the application\"\n        src=\"/static/383d2af1fcf9e2a16f2960de147ca549/e5715/383d2af1fcf9e2a16f2960de147ca549.png\"\n        srcset=\"/static/383d2af1fcf9e2a16f2960de147ca549/a6d36/383d2af1fcf9e2a16f2960de147ca549.png 650w,\n/static/383d2af1fcf9e2a16f2960de147ca549/e5715/383d2af1fcf9e2a16f2960de147ca549.png 768w,\n/static/383d2af1fcf9e2a16f2960de147ca549/aa878/383d2af1fcf9e2a16f2960de147ca549.png 1385w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<h2 id=\"summary\" style=\"position:relative;\"><a href=\"#summary\" aria-label=\"summary permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Summary</h2>\n<p>Azure key vault helps you to keep your application's secrets out of the application. You can use it to isolate secrets from your code files. These secrets include connection strings, API keys, environment variables, etc. You can take advantage of Azure Key Vault to keep secrets out of source control or out of your application in a centralized storage place. In this article, you've used managed identity to connect an Azure web app in .NET to an Azure Key Vault and retrieve secret value from there.</p>\n<p>The complete source code of the application discussed in this article can be found here: <a href=\"https://github.com/LoginRadius/engineering-blog-samples/pull/118\">Source Code</a></p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n  .dark-default-dark {\n    background-color: #1E1E1E;\n    color: #D4D4D4;\n  }\n  .dark-default-dark .mtk4 { color: #569CD6; }\n  .dark-default-dark .mtk1 { color: #D4D4D4; }\n  .dark-default-dark .mtk10 { color: #4EC9B0; }\n  .dark-default-dark .mtk11 { color: #DCDCAA; }\n  .dark-default-dark .mtk12 { color: #9CDCFE; }\n  .dark-default-dark .mtk15 { color: #C586C0; }\n  .dark-default-dark .mtk8 { color: #CE9178; }\n</style>","headings":[{"value":"Introduction","depth":2},{"value":"Prerequisites","depth":2},{"value":"What is Azure Key Vault?","depth":2},{"value":"Understanding Managed Identity","depth":2},{"value":"Create a Web App in the Azure Portal","depth":2},{"value":"Enable Managed Service Identity for your Web App","depth":3},{"value":"Create and Configure Azure Key Vault","depth":2},{"value":"Create a new Azure Key Vault Instance","depth":3},{"value":"Create an App Secret in Azure Key Vault","depth":3},{"value":"Authorize the Web App to access Your Key Vault","depth":3},{"value":"Create a New ASP.NET 5 Core application","depth":2},{"value":"Install the NuGet Packages","depth":3},{"value":"Read Azure Key Vault Secrets in .NET Core","depth":3},{"value":"Specify the Vault Uri in AppSettings","depth":4},{"value":"Access Secrets from AzureKeyVault","depth":4},{"value":"The KeyValueController Class","depth":4},{"value":"Register the Dependencies in the ConfigureServices Method","depth":4},{"value":"Deploy the Application to Azure","depth":2},{"value":"Execute the Application","depth":2},{"value":"Summary","depth":2}],"fields":{"slug":"/engineering/guest-post/using-azure-key-vault-with-an-azure-web-app-in-c-sharp/"},"frontmatter":{"metatitle":null,"metadescription":null,"description":"In this tutorial, you'll learn how to work with Azure Key Vault in C#.","title":"How to Use Azure Key Vault With an Azure Web App in C#","canonical":null,"date":"August 09, 2021","updated_date":null,"tags":["Azure","Key Vault","C#"],"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/bed799b83db7c1ce0146aeab64f8703a/03979/image.png","srcSet":"/static/bed799b83db7c1ce0146aeab64f8703a/f5f11/image.png 200w,\n/static/bed799b83db7c1ce0146aeab64f8703a/6d133/image.png 400w,\n/static/bed799b83db7c1ce0146aeab64f8703a/03979/image.png 800w,\n/static/bed799b83db7c1ce0146aeab64f8703a/aca38/image.png 1200w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Joydip Kanjilal","github":"joydipkanjilal","bio":"Microsoft MVP (2007 - 2012), Author and Speaker with more than 25 years experience. Familiar with C#, .NET Core, SQL Server, Microsoervices, Design Patterns, REST, GraphQL and Software Architecture","avatar":null}}}},"pageContext":{"id":"5ed0008b-aea3-5ad0-a188-c9d9ed140666","fields__slug":"/engineering/guest-post/using-azure-key-vault-with-an-azure-web-app-in-c-sharp/","__params":{"fields__slug":"engineering"}}},"staticQueryHashes":["1171199041","1384082988","1711371485","1753898100","2100481360","229320306","23180105","528864852"]}