1. 程式人生 > 其它 >AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware + Failed to authenticate HTTPS connection 異常的解決

AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware + Failed to authenticate HTTPS connection 異常的解決

使用VS新建一個Asp.Net Core空專案,將appsettings.Development.json檔案的"Microsoft": "Warning"改為"Microsoft": "Debug" , 執行!

結果倒好,看到了許多不該看的——開個玩笑了,能看到許多系統級的除錯資訊,本來是好事,可是ms你大爺的,一個新專案模板,我就改了五個字,怎麼就有異常了呢。

dbug: Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware[1]
      Failed to authenticate HTTPS connection.
      System.IO.IOException:  Received an unexpected EOF or 0 bytes from the transport stream.
         at System.Net.Security.SslStream.ReceiveBlobAsync[TIOAdapter](TIOAdapter adapter)
         at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter, Boolean receiveFirst, Byte[] reAuthenticationData, Boolean isApm)
         at Microsoft.AspNetCore.Server.Kestrel.Https.Internal.HttpsConnectionMiddleware.OnConnectionAsync(ConnectionContext context)

仔細一看有IOException異常啊,別的資訊無所謂,有異常說明程式執行有問題,這怎麼能忍。但再仔細看,這都什麼玩意,你讓初學者怎麼快快樂樂明明白白的往下學?你讓我這種完美主義者怎麼受得了!

網上搜索一下錯誤關鍵字“Failed to authenticate HTTPS connection”,在stackoverflow上找到一個解決方案,說是:

dotnet dev-certs https --clean
dotnet dev-certs https --trust

我試了一下,沒有作用,再繼續找,也沒找到個結果。鬱悶。咋回事呢。用IIS Express啟動除錯的時候,輸出可沒有這個異常,用專案自啟動(內建的Kestrel伺服器)除錯就異常。

看來應該是Kestrel伺服器方面的問題,而且和https有關,會不會是配置的問題,看了一下launchSettings.json配置檔案

每次執行專案,開啟的就是網址https://localhost:5001,會不會是url設定的問題,試著將"https://localhost:5001;http://localhost:5000"換一下順序,變為"http://localhost:5000;https://localhost:5001",再執行,我的天哪,沒有異常了,完美!

這是什麼原理,我去!

要是還想初次自動開啟網址https://localhost:5001,怎麼辦?有辦法,設定launchsettings.json檔案"launchUrl": "https://localhost:5001"

或者使用VS設定:

每次開啟的就是網址https://localhost:5001了。我容易嗎我,巨硬給新手挖這麼多坑。

——看完了文章,無論覺得寫的不錯的還是覺的辣雞的,可以點贊或給點意見,鼓勵或批評對我都很有用!