0

我有一个.net core 2.0使用IdentityServer 4的应用程序。它在开发模式下完美运行。然后我将其发布为生产模式并进行了测试。当我单击一个(该操作具有生成accesstoken的方法)链接时,出现如下错误,

发生未处理的异常:格式错误的 URL

然后在生产(发布)模式下发生错误:

var disco = await IdentityModel.Client.DiscoveryClient.GetAsync(_configuration.GetSection("Settings").GetSection("DiscoveryClient").Value);

上面DiscoveryClient不是 这里是错误的完整描述http..https

Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[0]
      An unhandled exception has occurred: Malformed URL
System.InvalidOperationException: Malformed URL
   at IdentityModel.Client.DiscoveryClient.ParseUrl(String input)
   at IdentityModel.Client.DiscoveryClient..ctor(String authority, HttpMessageHandler innerHandler)
   at IdentityModel.Client.DiscoveryClient.<GetAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

这是因为'https'。我不知道发生了什么。希望您对此有所帮助。

4

1 回答 1

0

这是DiscoveryClient的代码片段,ParseUrl它显示了它何时抛出该异常:

public static DiscoveryEndpoint ParseUrl(string input)
{
    var success = Uri.TryCreate(input, UriKind.Absolute, out var uri);
    if (success == false)
    {
        throw new InvalidOperationException("Malformed URL");
    }

    if (!DiscoveryEndpoint.IsValidScheme(uri))
    {
        throw new InvalidOperationException("Malformed URL");
    }

这是DiscoveryEndpoint方法的代码IsValidScheme

public static bool IsValidScheme(Uri url)
{
    if (string.Equals(url.Scheme, "http", StringComparison.OrdinalIgnoreCase) ||
        string.Equals(url.Scheme, "https", StringComparison.OrdinalIgnoreCase))
    {
        return true;
    }

    return false;
}

基于此,不会抛出异常,因为 url 正在使用http.

试着打电话

new Uri(_configuration.GetSection("Settings").GetSection("DiscoveryClient").Value, UriKind.Absolute)

在调用“IdentityModel.Client.DiscoveryClient.GetAsync”之前,您可以查看 Uri 构造函数引发的异常。

于 2018-09-15T05:54:32.463 回答