簡體   English   中英

發生未處理的異常:Malformed URL in Release mode in .net core 2.0 app

[英]An unhandled exception has occurred: Malformed URL in Release mode in .net core 2.0 app

我有一個使用IdentityServer 4.net core 2.0應用程序。 它在開發模式下完美運行。 然后我將其發布為生產模式並進行了測試。 當我單擊一個(該操作具有生成accesstoken的方法)鏈接時,出現如下錯誤,

發生未處理的異常:格式錯誤 URL

然后在生產(發布)模式下發生錯誤:

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

上面的DiscoveryClienthttp而不是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”。 我不知道發生了什么事。希望你能幫忙。

這是一篇很老的帖子,但它仍然可能對某人有所幫助。 我有這個完全相同的問題,只是我傳遞的 URL 完全沒問題。 我這邊的問題是IdentityServer Authority URL配置錯誤,導致它拋出相同的異常。

這是DiscoveryClientParseUrl代碼片段,顯示何時拋出該異常:

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");
    }

這是DiscoveryEndpointIsValidScheme方法的代碼:

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構造函數引發了什么異常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM