首页 > 解决方案 > 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)

感谢,任何快速响应。

标签: asp.netexception

解决方案


当我在 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>

推荐阅读