简体   繁体   English

XmlReader.Create错误“无法创建SSL / TLS安全通道”

[英]XmlReader.Create error “Could not create SSL/TLS secure channel”

On my ASP.net-based website I am aggregating feeds of my activities from several website. 在基于ASP.net的网站上,我正在汇总来自多个网站的活动的提要。 One of those is the GitHub feed at https://github.com/lucamauri.atom : this is a valid feed correctly readable using a web browser and it properly worked on my website since a couple of weeks ago. 其中之一是位于https://github.com/lucamauri.atom的GitHub提要:这是一个有效的提要,可以使用网络浏览器正确读取,并且从几周前开始就可以在我的网站上正常使用。 Since then, it started generating errors 从那时起,它开始产生错误

In the code I first create and XMLReader and then I load it in a SyndicationFeed object as follows: 在代码中,我首先创建并使用XMLReader ,然后将其加载到SyndicationFeed对象中,如下所示:

Dim TempReader As System.Xml.XmlReader = System.Xml.XmlReader.Create(TempString)
Dim SyndFeed As SyndicationFeed = SyndicationFeed.Load(TempReader)
Dim TempItems As New List(Of SyndicationItem)
TempItems.AddRange(SyndFeed.Items.ToList.GetRange(0, Math.Min(CurrentFeed.TotalElements, SyndFeed.Items.Count)))

This works properly with several feeds, but the GitHub one now generate a TLS error on the first row of the above code: 这可以在多个提要中正常工作,但是GitHub的提要现在在上述代码的第一行生成TLS错误:

System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel. System.Net.WebException:请求已中止:无法创建SSL / TLS安全通道。
at System.Net.HttpWebRequest.GetResponse() at System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy) 在System.Net.HttpWebRequest.GetResponse()在System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri,ICredentials凭据,IWebProxy代理,RequestCachePolicy cachePolicy)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy) 在System.Xml.XmlDownloadManager.GetStream处(Uri uri,ICredentials凭据,IWebProxy代理,RequestCachePolicy cachePolicy)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn) 在System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri,字符串角色,ObjectToReturn类型)
at System.Xml.XmlTextReaderImpl.FinishInitUriString() at System.Xml.XmlTextReaderImpl..ctor(String uriStr, XmlReaderSettings settings, XmlParserContext context, XmlResolver uriResolver) 在System.Xml.XmlTextReaderImpl..ctor处在System.Xml.XmlTextReaderImpl.FinishInitUriString()处(字符串uriStr,XmlReaderSettings设置,XmlParserContext上下文,XmlResolver uriResolver)
at System.Xml.XmlReaderSettings.CreateReader(String inputUri, XmlParserContext inputContext) 在System.Xml.XmlReaderSettings.CreateReader(String inputUri,XmlParserContext inputContext)
at System.Xml.XmlReader.Create(String inputUri, XmlReaderSettings settings, XmlParserContext inputContext) 在System.Xml.XmlReader.Create(String inputUri,XmlReaderSettings设置,XmlParserContext inputContext)
at System.Xml.XmlReader.Create(String inputUri) 在System.Xml.XmlReader.Create(String inputUri)

I use the same code with other HTTPS feeds ( https://stackoverflow.com/feeds/user/69295 just to name one) and I do not get the error. 我将相同的代码用于其他HTTPS提要(仅举一个例子, https://stackoverflow.com/feeds/user/69295https://stackoverflow.com/feeds/user/69295 ),但没有收到错误消息。 So this is something specific to the GitHub feed, but then again I can reach it from a browser on the same machine where I run the website, so I am lost at it. 因此,这是特定于GitHub提要的内容,但是再次可以从运行网站的同一台计算机上的浏览器访问它,所以我迷失了它。

Any idea on the cause of the issue? 对问题的原因有任何想法吗?

The server is in control of the protocol that is ultimately negotiated. 服务器控制最终协商的协议。 The Stackoverflow server is requiring only TLS v1 as shown in the wireshark capture below. Stackoverflow服务器仅需要TLS v1,如下面的wireshark捕获所示。 This trace was done on .Net framework version 4. 此跟踪是在.Net Framework版本4上完成的。

The Github feed refuses anything below TLS v1.2 and therefore fails on .Net 4.0 because that version is not available by default. Github提要拒绝TLS v1.2以下的任何内容,因此在.Net 4.0上失败,因为默认情况下该版本不可用。

在此处输入图片说明

You can work around it by setting the SecurityProtocol on the ServicePointManager, if you have .Net 4.5+ installed on the same computer . 如果在同一台计算机上安装了.Net 4.5+则可以通过在ServicePointManager上设置SecurityProtocol来解决此问题。 If you don't, then you simply cannot make the request. 如果您不这样做,那么您根本无法发出请求。

You do this by using the numeric value for the SecurityProtocol instead of the enumeration value which is not available on .Net 4. 通过使用SecurityProtocol的数字值而不是.Net 4上不可用的枚举值来执行此操作。

ServicePointManager.SecurityProtocol = DirectCast(3072, SecurityProtocolType)

在此处输入图片说明

Having done this, you can now negotiate TLS 1.2 even on .Net 4. However, if you can, just upgrade to a newer framework version to make it easy. 完成此操作后,您现在甚至可以在.Net 4上协商TLS 1.2。但是,如果可以,只需升级到较新的框架版本即可。

Update 更新资料

There is a patch available for .Net 3.5: .NET 3.5有一个修补程序:

https://support.microsoft.com/en-us/help/3154520/support-for-tls-system-default-versions-included-in-the-net-framework https://support.microsoft.com/zh-CN/help/3154520/support-for-tls-system-default-versions-included-in-the-net-framework

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

.NET 4.5.1 .NET 4.5.1

Set this in startup class of mvc project and xmlreader worked on https links, thanks guys. 在mvc项目的启动类中设置此项,谢谢xmlreader在https链接上工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TLS 1.2错误无法创建SSL / TLS安全通道 - TLS 1.2 error Could not create SSL/TLS secure channel 无法创建SSL / TLS安全通道-GetRequestStream() - Could not create SSL/TLS secure channel - GetRequestStream() Braintree 中的“请求被中止:无法创建 SSL/TLS 安全通道”错误 - "The request was aborted: Could not create SSL/TLS secure channel" error in Braintree RestSharp 请求中止 - 无法创建 SSL/TLS 安全通道 - RestSharp request aborted - could not create SSL/TLS secure channel 请求已中止:无法创建SSL / TLS安全通道 - request was aborted: Could not create SSL/TLS secure channel 该请求已中止:无法为HttpWebRequest创建SSL / TLS安全通道 - The request was aborted: Could not create SSL/TLS secure channel for HttpWebRequest Express PayPal结帐,无法创建SSL / TLS安全通道 - Express PayPal checkout, Could not create SSL/TLS secure channel IIS 2019:请求被中止:无法创建 SSL/TLS 安全通道 - IIS 2019: The request was aborted: Could not create SSL/TLS secure channel “无法创建SSL / TLS安全通道”:克隆如何工作? - “Could not create SSL/TLS secure channel”: how can the clone work? 无法创建从插件到Web服务的SSL / TLS安全通道 - Could not create SSL/TLS secure channel from plugin to web service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM