SecurityProtocolTypeExtensions.Tls12;在当前上下文中不存在 [英] SecurityProtocolTypeExtensions.Tls12; does not exist in current context

查看:1714
本文介绍了SecurityProtocolTypeExtensions.Tls12;在当前上下文中不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将安全协议更新到我现有的3.5 .net框架应用程序中,以使付款网关运行顺畅。我添加了以下代码

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

在我的 Global.asax 中c $ c> Application_Start ,但它给我带来了编译时错误


名称'SecurityProtocolTypeExtensions'不存在存在于
当前上下文中


我正在关注此链接S 支持。

更新1:



也尝试了上述链接中所述的方法,将两个文件都添加到了项目中,现在我出现异常 System.NotSupportedException :不支持所请求的安全协议



已更新2:



三由乔恩·戴维斯(Jon Davies)建议,但仍然没有运气。相同的异常 System.NotSupportedException

解决方案

此文章中介绍了此修复程序您已链接到:


要包括对TLS v1.2的支持,请在项目中包括源文件...


换句话说-您需要添加 SecurityProtocolTypeExtensions SslProtocolExtensions 从文章到您自己的项目。



这有点难看,但是因为TLS 1.2已发布 .NET 3.5之后。



或者,如果您想避免使用这些扩展名并且不介意代码中未标记的魔术数字,则可以忽略该代码在文章中,而是对其进行设置:

  System.Net.ServicePointManager.SecurityProtocol =(SecurityProtocolType)0x00000C00; 


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

解决方案

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;

这篇关于SecurityProtocolTypeExtensions.Tls12;在当前上下文中不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆