ASP.Net SecurityProtocol (for SSL Version Control)

By Akbar

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);

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;
}

I hope this helps.

Tags: , , ,