加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

如何在ASP.NET 2.0应用程序中为API调用启用TLS 1.2?

发布时间:2020-12-16 04:12:43 所属栏目:asp.Net 来源:网络整理
导读:我们的ASP.NET 2.0网站通过调用Authorize.Net的API来处理信用卡交易.授权已告知我们,在确定的日期,我们的客户必须使用TLS 1.2协议进行API调用. 微软似乎表明这个10-22-16 KB的文章中提供了一个解决方案:https://support.microsoft.com/en-us/help/3154517/s
我们的ASP.NET 2.0网站通过调用Authorize.Net的API来处理信用卡交易.授权已告知我们,在确定的日期,我们的客户必须使用TLS 1.2协议进行API调用.

微软似乎表明这个10-22-16 KB的文章中提供了一个解决方案:https://support.microsoft.com/en-us/help/3154517/support-for-tls-system-default-versions-included-in-the-.net-framework-2.0-sp2-on-windows-vista-sp2-and-server-2008-sp2

…we have added the SslProtocolsExtensions enumeration that you can
use as an option for setting TLS v1.2,TLS v1.1,as well as operating
system defaults for the ServicePointManager.SecurityProtocol property
when targeting .NET framework version 2.0 SP2.

请注意,尽管有本文的标题,但上述引用并未涉及Windows Vista SP2或Windows 2008 SP2操作系统,因为这些操作系统不支持TLS v1.1和1.2.

我已经通过以下步骤实现并测试了我对KB文章中指出的解决方案的理解:

>在我们的Windows Server 2008 R2 Web服务器上启用了TLS 1.2(并通过ssllabs.com确认).
>确认SP2实际上是为.NET framework 2.0版安装的.
>将引用的KB文章中显示的两个源文件添加到我们的项目中(即SecurityProtocolTypeExtensions.cs和SslProtocolsExtensions.cs)
>输入以下代码行(来自知识库文章)到API调用上方的项目:System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolTypeExtensions.Tls12;

不幸的是,在运行应用程序时,我在上面第3项中显示的代码行上遇到以下错误:

System.NotSupportedException: The requested security protocol is not
supported.

此时,我很难过.我特别感谢有关如何推进此解决方案的任何见解,但我有兴趣了解您所知道的任何其他方法,以允许来自ASP.NET 2.0应用程序的API调用来使用TLS 1.2. (升级到更新版本的.NET框架是最后的选择.)

在此先感谢您的帮助!

解决方法

我们不得不使用.NET 2.0应用程序迁移到TLS 1.2,我们不想将代码移植到.NET 4.5 / 4.6.经过几天的研究和遇到这篇文章后,我们找到了解决方案.这篇文章引用了错误的HOTFIX.要在Server 2008 R2上使用TLS 1.2 for .NET 2.0,您需要这个HOTFIX: https://support.microsoft.com/en-us/help/3154518/support-for-tls-system-default-versions-included-in-the-.net-framework

它引用了3.5.1框架,但ALSO适用于2.0框架.安装此修补程序后,您可以按照指示在服务器上进行注册表更改,或者在应用程序中更改代码以直接引用TLS 1.2.

C#
ServicePointManager.SecurityProtocol =(SecurityProtocolType)3072;

VB
ServicePointManager.SecurityProtocol = DirectCast(3072,System.Net.SecurityProtocolType)

对于其他操作系统,请查看Troy Starr的帖子:
https://community.qualys.com/thread/16917-net-framework

希望这可以帮助

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读