[英]TLS 1.2 .net 4.6.2 project
在Global.asax的Appliction_Start方法(MVC5项目)中,我具有应使用TLS1.2的这一行代码
if (ServicePointManager.SecurityProtocol.HasFlag(SecurityProtocolType.Tls12) == false)
{
ServicePointManager.SecurityProtocol = ServicePointManager.SecurityProtocol | SecurityProtocolType.Tls12;
}
检查价值
ServicePointManager.SecurityProtocol
在运行时显示此值
System.Net.SecurityProtocolType.Ssl3 | System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls12
因此,我假设正在使用TLS1.2,但是Firefox在控制台窗口中显示此消息
“此网站使用的TLS已弃用,将于2020年3月禁用。请升级到TLS 1.2或1.3”
如何确保使用TLS 1.2? 我正在使用.net Framework 4.6.2
在这行上:
ServicePointManager.SecurityProtocol = ServicePointManager.SecurityProtocol | SecurityProtocolType.Tls12;
您正在将 Tls12
添加到受支持的协议中。 在握手期间,将根据客户端的功能选择这些受支持的协议之一。 要仅支持Tls12
,请使用:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
.NET 4.6.2默认情况下应使用TLS 1.2。 您根本不需要的代码。 我的猜测是您可能使用了其他导致问题的httpRuntime
版本。
尝试从Global.asax
删除代码,并在web.config
显式设置httpRuntime
版本:
<system.web>
<httpRuntime targetFramework="4.6.2" />
</system.web>
我知道了,问题出在IIS express。 在本地运行网站并打开控制台窗口给了我TLS错误消息,但是当我运行在Azure中部署的网站时,我不再收到错误消息,所以一定是因为我是通过IIS express在本地运行的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.