如何設定 .NET Framework 支援 TLS 1.2
3.5.1或以下版本,無法支援,建議更新版本至4.6以上版本
如為4.0版本,無法支援,請額外安裝4.5.2以上之版本,
並參考以下範例修改,程式修改或系統機碼設定擇一即可
程式修改參考:
ServicePointManager.SecurityProtocol = (SecurityProtocolType)768 | (SecurityProtocolType)3072;
系統機碼設定參考:
https://blogs.msdn.microsoft.com/jchiou/2016/05/27/%E5%A6%82%E4%BD%95%E5%9C%A8-net-framework-4-0-4-5-%E4%BB%A5%E4%B8%8A%E7%9A%84%E7%A8%8B%E5%BC%8F%E6%94%AF%E6%8F%B4-tls-1-2/
如為.Net Framework4.5.2版本,請參考以下範例修改,程式修改或系統機碼設定擇一即可
程式修改參考:
//Creating the Web Request.
HttpWebRequest httpWebRequest = null;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(AcceptAllCertifications);
httpWebRequest = WebRequest.Create(requestUrl) as HttpWebRequest;
httpWebRequest.ProtocolVersion = HttpVersion.Version10;
系統機碼設定參考:
https://blogs.msdn.microsoft.com/jchiou/2016/05/27/%E5%A6%82%E4%BD%95%E5%9C%A8-net-framework-4-0-4-5-%E4%BB%A5%E4%B8%8A%E7%9A%84%E7%A8%8B%E5%BC%8F%E6%94%AF%E6%8F%B4-tls-1-2/
如為4.6版本以上版本無須修改
|