ASP.Net SecurityProtocol (for SSL Version Control)
Recently, when working on an integration API written in ASP.Net which communicates with a web-services developed using PHP, the tech support requested to force all the secure communication (over HTTPS) to use only the SSL v3 version.
This can be controlled in PHP CURL via single line of code as shown blow:
1 | curl_setopt($curl, CURLOPT_SSLVERSION,3); |
curl_setopt($curl, CURLOPT_SSLVERSION,3);
For more details on this, please check curl-setopt. Doing this in the ASP.Net was a single line of code as well, but finding it was not that easy. Here is the code which did the trick for me:
1 2 3 4 5 6 7 8 9 10 11 12 13 | try { // Take back-up of current protocl and force use of only SSL3 SecurityProtocolType activeProtocol = ServicePointManager.SecurityProtocol; ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3; // The ASP.Net communciation (using HttpWebRequest) goes here } catch {} finally { // Restore the orignal protocol ServicePointManager.SecurityProtocol = activeProtocol; } |
try { // Take back-up of current protocl and force use of only SSL3 SecurityProtocolType activeProtocol = ServicePointManager.SecurityProtocol; ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3; // The ASP.Net communciation (using HttpWebRequest) goes here } catch {} finally { // Restore the orignal protocol ServicePointManager.SecurityProtocol = activeProtocol; }
I hope this helps.
Tags: ASP.Net, HTTP, SSL, Version
This entry was posted
on Thursday, January 3rd, 2013 at 3:38 pm and is filed under ASP.Net, C#.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
Feedback & Comments
No Responses