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",再运行,我的天哪,没有异常了,完美!

不过就是自动打开的网指是第一个即http://localhost:5000了。这是什么原理,我去!

要是还想初次自动打开网址https://localhost:5001,怎么办?有办法,设置launchsettings.json文件"launchUrl": "https://localhost:5001"或者使用VS设置:

每次打开的就是网址https://localhost:5001了。我容易吗我,巨硬给新手挖这么多坑。

专门去官方提交了bug反馈,结果说这是无害级调试日志。还是我这个办法可以暂时抑制异常信息。

posted @ 2021-08-01 20:24  黑衫老腰  阅读(729)  评论(0编辑  收藏  举报