JLu*_*nda 2 asp.net identity azure visual-studio azure-web-app-service
我遇到了以下情况并最终解决了问题:
我有一个 ASP.NET 应用程序,它通过 AzureKeyVaultConfigBuilder 对 Azure Key Vault 具有运行时依赖性。使用 Visual Studio 2019 从我的本地计算机运行,只要将我的工作 (@microsoft.com) 帐户添加到 Visual Studio,它就能够访问 Key Vault。但是,如果我将个人 Microsoft 帐户 (@live.com) 和工作帐户 (@microsoft.com) 添加到 Visual Studio,则应用程序会尝试使用我的个人 Microsoft 帐户 (@live.com) 对 Key Vault 进行身份验证),当它应该使用工作 (@microsoft.com) 帐户时。
当两个帐户都登录到 Visual Studio 时,我收到以下异常:
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: The configBuilder 'AzureKeyVault' failed while processing the configuration section 'appSettings'.: Error in Configuration Builder 'AzureKeyVault'::GetValue(AzureStorageConnectionString)
Source Error:
Line 32: </builders>
Line 33: </configBuilders>
Line 34: <appSettings configBuilders="AzureKeyVault">
Line 35: <add key="AzureStorageConnectionString" value="" />
Line 36: </appSettings>
Source File: C:\<path to ASP.NET Web project>\web.config Line: 34
Click here to show additional error information:
Exception Details: Azure.Identity.CredentialUnavailableException: DefaultAzureCredential failed to retrieve a token from the included credentials.
EnvironmentCredential authentication unavailable. Environment variables are not fully configured.
ManagedIdentityCredential authentication unavailable, no managed identity endpoint found.
SharedTokenCacheCredential authentication unavailable. Multiple accounts were found in the cache. Use username and tenant id to disambiguate.
Run Code Online (Sandbox Code Playgroud)
我经历了大量的试验和错误,在环境变量级别、Visual Studio 级别和 Azure CLI 级别设置凭据,但当在 Visual Studio 中注册多个帐户时,这些都没有得到尊重。
问题出在 Azure.Identity 包上,该包用于根据 Azure 开发环境对 ASP.NET 应用程序进行身份验证。我安装了 1.1.1 版本的软件包。版本 1.2.0 和 1.3.0 中修复了并发调用 DefaultAzureCredential 的多个问题。因此,更新到版本 1.3.0 解决了我的问题并正确尊重了VisualStudioCredential 的设置。
DefaultAzureCredential指定从各种源获取不同身份验证令牌的控制流。
| 归档时间: |
|
| 查看次数: |
6540 次 |
| 最近记录: |