在 Framework 4.0 中,SecurityProtocolType.Tls11 和 SecurityProtocolType.Tls12 枚举值缺失。
SecurityProtocolType 数值对应关系:
SystemDefault (0)
Ssl3 (48 - 0x30)
Tls (192 - 0xC0)
Tls11 (768 - 0x300) 在 Framework 4.0 缺失
Tls12 (3072 - 0xC00) 在 Framework 4.0 缺失
若要在 Framework 4.0 中允许使用 TLS 1.0、1.1 和 1.2,请将以下内容替换:
SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12
作者:
(SecurityProtocolType)(0xc0 | 0x300 | 0xc00)
SecurityProtocolType.SystemDefault
(0x00) 选项,但在某次更新后又消失了。 - Louis SomersTLS及如何避免连接错误。
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
就我个人而言,在我的.NET 4.0框架中,我使用了一些asp经典文件:
ServicePointManager.SecurityProtocol = (SecurityProtocolType)(0xc0 | 0x300 | 0xc00);
https://blogs.perficient.com/2016/04/28/tsl-1-2-and-net-support/
您是否在使用 .NET Framework 4.0?建议您至少升级到 4.5 版本。您可以尝试更新您的 Web 目标框架版本: .NET Framework 4.0 中的 TLS 1.2
对于vb.net
ServicePointManager.SecurityProtocol = DirectCast(&HC0 Or &H300 Or &HC00, SecurityProtocolType)
这个网站已经在 .Net 4.5 上运行,手动将 Compilation > TargetFramework 从 4.0 更新到 4.5 后,问题得到了解决。
以下是更新后的配置:
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Net, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
</assemblies>
</compilation>
ServicePointManager.SecurityProtocol = (SecurityProtocolType)(0xc0 | 0x300 | 0xc00);
关于您所关心的应用程序(客户端)和服务器将使用哪个版本的TLS。
以下是从RFC 5246 TLS标准中直接引用的内容。
在 ClientHello
中(客户端向服务器发出的第一个请求)
客户端希望在此会话期间使用的TLS协议版本。这应该是客户端支持的最新(最高价值)版本。
在 ServerHello
中(服务器响应的第一个请求)
该字段将包含客户端建议的版本和服务器支持的最高版本中较低的一个。
ClientHello
和ServerHello
是具有字段的结构,这些字段在标准此处中进行了描述。
简而言之
当使用System.Net.WebRequest
时,您的应用程序将与服务器协商确定双方都支持的最高TLS版本,并使用它。
关于您的问题。
=
符号。这将删除所有其他内容,只留下Tls12
。请改用|=
。 - kuskmen