Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SecurityProtocolTypeExtensions.Tls12; does not exist in current context

I am updating Security protocols to my existing 3.5 .net framework application to work my payment gateways smooth. I have added following code

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolTypeExtensions.Tls12;

in my Global.asax in Application_Start but it is giving me compile time error that

The name 'SecurityProtocolTypeExtensions' does not exist in the current context

I was following this link Support for TLS System Default Versions included in the .NET Framework 3.5.1 on Windows 7 SP1 and Server 2008 R2 SP1 provided by Microsoft.

Update 1:

Also tried as told in above link, added both files in project, now I am getting an exception "System.NotSupportedException: The requested security protocol is not supported"

Updated 2:

Tried as suggested by Jon Davies, but still no luck. same Exception System.NotSupportedException

like image 590
trighati Avatar asked Jan 31 '17 10:01

trighati


1 Answers

The fix is stated in the article you linked to:

To include the support for TLS v1.2, include the source files in your project...

In other words - you need to add the SecurityProtocolTypeExtensions and SslProtocolExtensions types from the article to your own project.

It's a bit of an ugly hack, but is required because TLS 1.2 was released after .NET 3.5.

Alternatively if you want to avoid using these extensions and don't mind unlabelled magic numbers in your code, you could ignore the code in the article and just set this instead:

System.Net.ServicePointManager.SecurityProtocol = (SecurityProtocolType)0x00000C00;
like image 86
Jon Davies Avatar answered Sep 27 '22 20:09

Jon Davies