SecurityProtocolTypeExtensions.Tls12; does not exist in current context

心已入冬 提交于 2019-12-01 04:38:37

问题


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


回答1:


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;


来源:https://stackoverflow.com/questions/41955081/securityprotocoltypeextensions-tls12-does-not-exist-in-current-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!