【问题标题】:SecurityProtocolTypeExtensions.Tls12; does not exist in current contextSecurityProtocolTypeExtensions.Tls12;在当前上下文中不存在
【发布时间】:2017-06-16 17:48:41
【问题描述】:

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

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

在我的Global.asaxApplication_Start 中,但它给了我编译时错误

名称“SecurityProtocolTypeExtensions”不存在于 当前上下文

我正在关注微软提供的这个链接 Support for TLS System Default Versions included in the .NET Framework 3.5.1 on Windows 7 SP1 and Server 2008 R2 SP1

更新 1:

还按照上面链接中的说明进行了尝试,在项目中添加了两个文件,现在我收到异常“System.NotSupportedException:不支持请求的安全协议”

更新 2:

按照 Jon Davies 的建议进行了尝试,但仍然没有运气。同样的异常System.NotSupportedException

【问题讨论】:

    标签: c# asp.net .net-3.5 tls1.2


    【解决方案1】:

    您链接到的文章中说明了该修复:

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

    换句话说 - 您需要将文章中的 SecurityProtocolTypeExtensionsSslProtocolExtensions 类型添加到您自己的项目中。

    这有点难看,但因为 TLS 1.2 是在 在 .NET 3.5 之后发布的,所以它是必需的。

    或者,如果您想避免使用这些扩展并且不介意代码中未标记的幻数,您可以忽略本文中的代码并直接设置:

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

    【讨论】:

    • 我应该从哪里得到这些源文件,
    • 复制文章开发者指南部分的定义。
    • 我应该在哪里保存该代码,因为它看起来在 System.Net 命名空间内部,即 .net 核心类
    • 只需将它们包含在您自己的项目中 - 您可能必须关闭一些命名空间检查规则,否则它应该可以正常工作。
    • 非常感谢@Jon Davies,您为我节省了几天的工作量,而不是针对 .Net 4.5,我使用了您的 hack,它奏效了!
    【解决方案2】:

    还要检查使用 System.Security.Authentication 在文件的顶部

    【讨论】:

      猜你喜欢
      • 2023-03-30
      • 2020-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多