asp.net - IOException:IDX20807:无法从“System.String”检索文档。HttpResponse 消息:
问题描述
我正在使用 Asp.Net Core 3.1 并通过 Challenge 方法,调用外部端点进行身份验证
public async Task<IActionResult> Challenge(string provider, string returnUrl,string userName)
{
var props = new AuthenticationProperties
{
RedirectUri = Url.Action(nameof(Callback)),
Items =
{
{ "returnUrl", returnUrl },
{ "scheme", provider },
},
Parameters =
{
{ OidcConstants.AuthorizeRequest.LoginHint, userName }
}
};
var result = Challenge(props, provider);
return result;
}
错误:
An unhandled exception occurred while processing the request.
IOException: IDX20807: Unable to retrieve document from: 'System.String'. HttpResponseMessage: 'System.Net.Http.HttpResponseMessage', HttpResponseMessage.Content: 'System.String'.
Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(string address, CancellationToken cancel)
InvalidOperationException: IDX20803: Unable to obtain configuration from: 'System.String'.
Microsoft.IdentityModel.Protocols.ConfigurationManager<T>.GetConfigurationAsync(CancellationToken cancel)
感谢,任何快速响应。
解决方案
当我在 Visual Studio 2019 中创建一个新的 .NET 5 项目时遇到了这个异常。
IOException:IDX20807:无法从“System.String”检索文档。HttpResponseMessage:'System.Net.Http.HttpResponseMessage',HttpResponseMessage.Content:'System.String'。Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(string address, CancellationToken cancel) Microsoft.IdentityModel.Protocols.OpenIdConnect.OpenIdConnectConfigurationRetriever.GetAsync(string address, IDocumentRetriever retriever, CancellationToken cancel) Microsoft.IdentityModel.Protocols.ConfigurationManager.GetConfigurationAsync(CancellationToken cancel)
在启动应用程序之前,我收到此错误:
所需组件 -dotnet msidentity tool
您可以在连接的服务 - 服务依赖项中修复此问题,并通过按配置来设置 Microsoft 标识平台。
对我来说,它就像这样卡住了,但什么也没发生:
然后我appsettings.json
找到了以下代码:
/*
The following identity settings need to be configured
before the project can be successfully executed.
For more info see https://aka.ms/dotnet-template-ms-identity-platform
*/
访问https://aka.ms/dotnet-template-ms-identity-platform并改用该工具msidentity-app-sync
。首先安装它,然后验证我是否安装了该工具。
dotnet tool install -g msidentity-app-sync
dotnet tool list -g
然后msidentity-app-sync
在项目文件夹中运行。App registrations
将在其中创建一个新Azure Active Directory
项目,该项目现在可以运行。
如果您希望使用这样的现有应用程序,您还可以自己指定租户和客户:
msidentity-app-sync --tenant-id <tenant-id> --username <username> --client-id <client-id>
推荐阅读
- java - 比较器声明语法
- python - AttributeError:模块“blog.views”没有属性“new_comment”
- rasa - 发送消息时 Rasa 崩溃
- pdf - pdf tounicode 将 cid 映射到不正确的字符
- c - C中的细胞功能
- css - 您如何在电子中自定义滚动条?
- javascript - 为什么从渲染方法中取出 setState 会使其无法在反应中工作?
- python - ValueError:无法将大小为 108900 的数组重塑为形状 (200,200,3)
- pytorch - 使用 "apex" 和 "nn.Embedding" 权重矩阵而不指定 float16 报告类型错误
- automation - Excel 自动化无处不在