AzureKeyVault ConfigurationBuilder 中的connectionString 属性是什么样的?

bea*_*ous 3 asp.net-mvc .net-framework-version azure-keyvault visual-studio-2017

我尝试在 .NET 4.7.1 MVC 应用程序中使用新的 AzureKeyVault ConfigurationBuilder,但在本地运行时不断出现配置错误:

Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 

Parser Error Message: An error occurred loading a configuration file: One or more errors occurred.

Source Error: 


Line 13:     </builders>
Line 14:   </configBuilders>
Line 15:   <appSettings configBuilders="AzureKeyVault">
Line 16:     <add key="webpages:Version" value="3.0.0.0" />
Line 17:     <add key="webpages:Enabled" value="false" />
Run Code Online (Sandbox Code Playgroud)

创建新的 .NET Framework 4.7.1 ASP.NET MVC Web 项目后,我将连接的服务添加到 Azure Key Vault 并定位到现有的保管库。然后我的 web.config 看起来包含了这一部分:

<configuration>
  <configSections>
    <section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false" />
  </configSections>
  <configBuilders>
    <builders>
      <add name="AzureKeyVault" vaultName="my-test-keyvault" connectionString="" type="Microsoft.Configuration.ConfigurationBuilders.AzureKeyVaultConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Azure, Version=1.0.0.0, Culture=neutral" vaultUri="https://WebApplication1-12-kv.vault.azure.net" />
    </builders>
  </configBuilders>
  <appSettings configBuilders="AzureKeyVault">
    <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>
  <system.web>
    <compilation debug="true" targetFramework="4.7.1" />
    <httpRuntime targetFramework="4.7.1" />
Run Code Online (Sandbox Code Playgroud)

我一直在互联网上搜索,试图找到连接字符串应该是什么样子的示例,但我没有取得任何成功。文档指出:

保管库名称是必需的。其他属性允许您对要连接到的保管库进行一些手动控制,但仅当应用程序未在与 Microsoft.Azure.Services.AppAuthentication 完美配合的环境中运行时才需要。如果可能,Azure 服务身份验证库用于自动从执行环境中获取连接信息,但您可以通过提供连接字符串来覆盖该功能。

这里有什么建议或指示吗?谢谢。

bea*_*ous 5

链接文章(宣布 .NET 4.7.1 云工具)中链接的文档已过时。AzureKeyVaultConfigBuilder 类上没有clientIdclientSecret属性。

但是有一个connectionString属性。有关如何在本地运行时构建该连接字符串的详细信息,请参阅本文:使用 .NET 对 Azure Key Vault 进行服务到服务身份验证

这是对我有用的方法:

RunAs=App;AppId={AppId};TenantId={TenantId};AppKey={ClientSecret}
Run Code Online (Sandbox Code Playgroud)

所有这三个值(AppId、TenantId 和 AppKey)均可在 Azure 中应用程序的 AD 条目中找到。