net 5.0 无法确定帧大小或收到损坏的帧 [英] net 5.0 Cannot determine the frame size or a corrupted frame was received

查看:36
本文介绍了net 5.0 无法确定帧大小或收到损坏的帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想试试net5.0,因为它在rc2中,我遇到了一个奇怪的问题.

I want to try net5.0 since it's in rc2, and I've encountered a strange issue.

我在 net5.0 中创建了一个默认的 WebApi.我没有碰任何东西,我只是点击了运行(在 kestrel 中,而不是 ISS),然后 Swagger 主页就会出现.我尝试了 WeatherForcast,一切正常.

I've created a default WebApi in net5.0. I didn't touch anything, I just clicked run (in kestrel, not ISS) and the Swagger home page shows up. I tried the WeatherForcast get and everything is working fine.

然后我在 NET5.0 中创建了一个控制台应用程序并添加了以下代码:

then I created a console app in NET5.0 and added this code :

static async Task Main(string[] args)
{
    var clientHandler = new HttpClientHandler
    {
        ServerCertificateCustomValidationCallback = (_, _, _, _) => true
    };
    var client = new HttpClient(clientHandler);
    try
    {
        var httpMessage = await client.GetAsync("https://localhost:5001/WeatherForecast");
    }
    catch (Exception e)
    {
        Console.WriteLine(e);
        throw;
    }
}

使用此代码,我收到以下错误:

and with this code I got the following error :

System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
---> System.IO.IOException: Cannot determine the frame size or a corrupted frame was received.

在那之后,我在 Postman 上尝试了相同的请求并且它起作用了(从 swagger 开始).我的最终测试是将控制台应用程序切换到 netcore 3.1 并且请求有效.

after that, I tried on Postman the same request and it worked (as from swagger). My final test was to switch the console app to netcore 3.1 and the request worked.

所以我只在 net5.0 应用上遇到了这个错误.

So I only got this error on net5.0 app.

有什么建议吗?

  • 这是我的电脑信息:W10 Enterprise,V 1809,Build 17763.1518.
  • 我只在 Net5.0 控制台上收到错误消息.

推荐答案

Kestrel 用于强制选择 Tls 1.1 或 Tls 1.2.从 .Net 5.0 Preview 6 开始,它更改为None",即操作系统默认值.Kestrel 默认 TLS 支持

Kestrel used to force selection of Tls 1.1 or Tls 1.2. From .Net 5.0 Preview 6 onwards, it was change to "None", meaning the OS default. Kestrel Default Tls Support

巧合的是,微软去年开始在 Windows 10 中默认启用 Tls 1.3.Windows 10 Tls 1.3 默认启用因此您的应用程序现在可能正在使用 Tls 1.3,我发现它有时有问题".

Coincidentally, Microsoft last year started enabling Tls 1.3 by default in Windows 10. Windows 10 Tls 1.3 Enabled by DefaultHence your application is likely now using Tls 1.3 which I have found to be sometimes "problematic".

要将 Tls 1.3 设置为默认禁用(意味着可用于请求它的应用程序,否则关闭),请在您的注册表中转到或创建此路径:

To set Tls 1.3 to be disabled by default (meaning available to apps that request it, but off otherwise), in your registry go to or create this path:

HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSecurityProvidersSCHANNELProtocolsTLS 1.3Client

并将名为 DisabledByDefault 的 DWORD 设置或创建为 1.

And set or create a DWORD named DisabledByDefault to 1.

这将使您的浏览器与 Tls 1.2 兼容.

This should make your browser go with Tls 1.2.

对于您的 Kestrel 服务器,类似地:

For your Kestrel server, similarly:

HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSecurityProvidersSCHANNELProtocolsTLS 1.3Server

还有,将名为 DisabledByDefault 的 DWORD 设置或创建为 1.

Also there, set or create a DWORD named DisabledByDefault to 1.

如果不这样做,则在客户端和服务器下还要创建一个名为已启用"的 DWORD;设置为 0.这将完全禁用 Tls 1.3.

If that doesn't do it, under both Client and Server also create a DWORD named "Enabled" set to 0. This will disable Tls 1.3 altogether.

这篇关于net 5.0 无法确定帧大小或收到损坏的帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆