asp.net-mvc - AzureKeyVault ConfigurationBuilder 中的 connectionString 属性是什么样的?
问题描述
我正在尝试在 .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" />
创建新的 .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" />
我一直在网上搜索,试图找到 connectionString 应该是什么样子的例子,但我没有任何成功。该文档指出:
VaultName 是必需的。其他属性允许您手动控制要连接到哪个保管库,但仅当应用程序未在与 Microsoft.Azure.Services.AppAuthentication 神奇协作的环境中运行时才需要。如果可能,Azure 服务身份验证库用于从执行环境中自动获取连接信息,但您可以通过提供连接字符串来替代该功能。
这里有什么建议或指示吗?谢谢。
解决方案
链接文章(宣布 .NET 4.7.1 云端工具)中链接的文档已过期。AzureKeyVaultConfigBuilder 类上没有clientId和clientSecret属性。
但是有一个connectionString属性。本文详细介绍了如何在本地运行时构建该连接字符串:使用 .NET 对 Azure Key Vault 进行服务到服务身份验证。
这是对我有用的方法:
RunAs=App;AppId={AppId};TenantId={TenantId};AppKey={ClientSecret}
所有这三个值(AppId、TenantId 和 AppKey)都在 Azure 中应用程序的 AD 条目中可用。
推荐阅读
- arrays - 将数组放入新工作表?
- jvm - 关于预写屏障的 g1 gc 问题
- docker - Kubernetes本地最佳方式4
- image - 大会 x86:如何显示转换为零和一的图像?
- linux - AWS EFS:如何浏览文件?
- linux - Arch Linux:PyCharm 不使用 Jetbrains 平台
- codeigniter-4 - 如何在 codeignitor 4 中验证 rest api postdata 以及如何在 $validation->check($value, 'required') 中添加自定义错误消息?
- c++ - 如何迭代我不知道名称或数量的文件?
- java - BorderLayout.North 中的 JScrollPane 是隐藏的,除非它是全屏的
- javascript - 如何将生成的画布元素传递给Vue中的子组件?