[英]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.