Tuesday, February 26, 2019

Http TLS Support for Legacy framework

   Recently i faced issue to make http call to WebAPI which is supporting latest TLS12 or TLS11. But our client project framework uses .net 4.0 so it not support by default. To resolve this issue added below code (constructor of API or global level)


 //Setting supported security protocol

   System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | (SecurityProtocolType)((SslProtocols)0x00000C00) | (SecurityProtocolType)((SslProtocols)0x00000300);



Here 

(SecurityProtocolType)((SslProtocols)0x00000C00) is equivalent to Tls12
(SecurityProtocolType)((SslProtocols)0x00000300) is equivalent to Tls11



Ref: https://support.microsoft.com/en-us/help/3154520/support-for-tls-system-default-versions-included-in-the-net-framework