c# - 具有 App Config 和托管标识的 Azure 函数 - 如何在本地调试
问题描述
我一直在到处寻找标题中问题的答案,但我发现关于我的问题的相关信息为 0,是的,有其他服务的示例,但我的情况没有。
我有一个 Azure 应用程序功能。
我启用了它的托管身份。
我在应用程序配置访问管理 (IAM) 中为该功能添加了数据读取者角色。
在我的代码中我添加了
public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
{
var appConfigEndpoint = Environment.GetEnvironmentVariable("AppConfigEndpoint");
builder.ConfigurationBuilder.AddAzureAppConfiguration(options => options.Connect(new Uri(appConfigEndpoint), new ManagedIdentityCredential()));
}
在我的 Startup.cs
当我在本地调试中运行它时,我收到此错误:
A host error has occurred during startup operation '<some GUID>'.
Azure.Identity: ManagedIdentityCredential authentication unavailable. No Managed Identity endpoint found.
Value cannot be null. (Parameter 'provider')
也尝试改变new ManagedIdentityCredential()
,new DefaultAzureCredential()
但后来我得到:
A host error has occurred during startup operation '732e2be5-0729-4279-b15a-833c8313b39a'.
Azure.Data.AppConfiguration: Service request failed.
Status: 403 (Forbidden)
Headers:
Server: openresty/1.17.8.2
Date: Wed, 30 Jun 2021 14:15:22 GMT
Connection: keep-alive
x-ms-request-id: 2f2066ef-9222-42d5-b96b-85a9b338127e
x-ms-client-request-id: 68cd19e1-0166-4567-a3f9-10f9a1cb6f3c
x-ms-correlation-request-id: 2f2066ef-9222-42d5-b96b-85a9b338127e
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: DNT, X-CustomHeader, Keep-Alive, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Authorization, x-ms-client-request-id, x-ms-useragent, x-ms-content-sha256, x-ms-date, host, Accept, Accept-Datetime, Date, If-Match, If-None-Match, Sync-Token, x-ms-return-client-request-id, ETag, Last-Modified, Link, Memento-Datetime, retry-after-ms, x-ms-request-id, x-ms-client-session-id, x-ms-effective-locale, WWW-Authenticate
Strict-Transport-Security: max-age=15724800; includeSubDomains
Content-Length: 0
.
Value cannot be null. (Parameter 'provider')
我的 Azure 帐户被添加到我的 Visual Studio 并在工具 > 选项 > Azure 服务身份验证中被选中。
我快疯了 - 我必须做什么才能在本地调试?
解决方案
ManagedIdentityCredential
仅适用于 Azure。您可以将其更改为使用DefaultAzureCredential
。它尝试多种方法,包括托管标识和 Visual Studio 身份验证。所以它也可以在本地工作。当然,您的用户帐户也需要具有所需的 RBAC 角色。
推荐阅读
- python - 熊猫,索引是一个元组(名称,日期),按日期范围排序?
- localization - 本地化后立即更新所有具有文本的元素
- python - 打开所有文本文件并在 python 中获取一个字符串
- python - 如何为机器学习方法编码我的数据?
- typescript - 在 Typescript 中转换函数参数对象属性
- autohotkey - AHK 发送密钥随机次数
- wpf - WPF - 如何让动态添加的菜单项助记符起作用
- javascript - Jquery加载多个警报
- c# - 打开包含文件的文件夹并将名称传输到列表框。双击然后转移到文本框
- python - 使用 Python 3.6 通过 SSH 隧道连接到远程 MySQL 数据库时遇到问题?