gpt4 book ai didi

azure - 如何在应用程序中使用连接字符串的 Azure KeyVault 引用

转载 作者:行者123 更新时间:2023-12-04 17:33:44 25 4
gpt4 key购买 nike

更新:修复位于我下面的评论中。版主可以将其固定为答案吗?谢谢!

我正在尝试设置 Azure KeyVault,而不对 Web.Config 文件进行任何代码更改。我有一个 Web 应用程序,它有一个用于数据存储的 SQL 数据库,我正在尝试以这种方式替换 connectionString,以便在使用 Azure 应用服务配置部署应用程序期间动态注入(inject)它。我正在使用对我的 key 保管库 secret 的引用来在我的应用程序服务配置中引用它。但是,我无法访问数据,并且收到以下错误:

/image/oBx8H.jpg

我尝试过以下方法:

  1. 创建 KeyVault 实例
  2. 向 KeyVault 添加 secret
  3. 授予 Web 应用程序访问权限,以便能够使用 Azure Active Directory 访问此 KeyVault。我创建了一个新的应用程序注册,分配了 key 保管库的访问策略,以便为该事件目录提供能够访问/设置/获取/列出 secret 的所有权限。
  4. 通过转到我的应用服务、配置并添加连接字符串,将 Key Vault 集成到我的 Azure 应用服务中,如下所示:

/image/RMyAg.jpg

如您所见,我使用来自 KeyVault 的引用,形式如下:

@Microsoft.KeyVault(SecretUri= https://xxx.vault.azure.net/secrets/mysecret/xxxzxxzxxzxzx )

我什至尝试使用这样的引用:

@Microsoft.KeyVault(VaultName=xxx-kv-arm;SecretName=connectionString;SecretVersion=xxx)

在我的 Azure 应用服务配置中访问 key 保管库中的 secret ,并在部署期间将其作为连接字符串传递。

我的 Web.config:

<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="SchoolContext" connectionString=" " providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>

</configuration>

我到底做错了什么?

最佳答案

However, I do not see this app service in my azure active directory, any clues as to why this is?

您可以在企业应用程序下找到该应用程序,记得将应用程序类型设置为所有应用程序

enter image description here

该问题已由操作解决,只需将其添加到答案中以使其对其他人可见。

转到“应用程序服务”,转到“身份”,然后启用系统分配的身份。这将允许我们转到我的 Key Vault 实例并为此应用服务本身(而不是新的 Azure Active Directory)配置访问策略。

这是document供您引用。

关于azure - 如何在应用程序中使用连接字符串的 Azure KeyVault 引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57564254/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com