最近,我们的一个ASP.NET ASHX处理程序在另一个服务器上调用另一个ASHX处理程序时开始失败,但出现了以下错误:“未处理的异常: System.Net.WebException:请求被中止:无法创建SSL/TLS安全通道”。为另一个服务器安装证书没有帮助(在任何情况下,另一个服务器是面向公共的,并且具有由CA签名的证书)。
我编写了一个小型C#程序来测试是否可以从命令行连接到另一个服务器:
using System.Net;
public class Test
{
const string theUrl = "https://www.example.com/Handler.ashx?ID=123";
public static void Main(string[] args)
{
var req = WebRequest.Create(theUrl);
var resp = req.GetResponse();
}
}
对于System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel
来说,这也是失败的。但是,如果我从VBScript文件调用处理程序:
Const theUrl = "https://www.example.com/Handler.ashx?ID=123"
Dim oXmlHttp
Set oXmlHttp = WScript.CreateObject("Microsoft.XMLHTTP")
With oXmlHttp
.Open "GET", theUrl, False
.Send
WScript.Echo CStr(.Status)
End With
Set oXmlHttp = Nothing
它可以工作;脚本返回状态为200!
我检查了.NET machine.config
文件,因为我在过去遇到了一个类似的问题,非托管代码发送的请求可以工作,但是来自.NET的请求不起作用,因为代理设置不同,但这里的情况并非如此。为什么来自VBScript的请求应该工作,但是来自.NET的请求失败呢?
编辑:启用跟踪显示类似于这个问题中报告的错误
System.Net Information: 0 : [28468] InitializeSecurityContext(credential = System.Net.SafeFreeCredential_SECURITY, context = 1ad5f0:29f3620, targetName = www.example.com, inFlags = ReplayDetect, SequenceDetect, Confidentiality, AllocateMemory, InitManualCredValidation)
System.Net Information: 0 : [28468] InitializeSecurityContext(In-Buffers count=2, Out-Buffer length=0, returned code=AlgorithmMismatch).
System.Net.Sockets Verbose: 0 : [28468] Socket#3741682::Dispose()
System.Net Error: 0 : [28468] Exception in the HttpWebRequest#2383799:: - The request was aborted: Could not create SSL/TLS secure channel.
System.Net Error: 0 : [28468] Exception in the HttpWebRequest#2383799::GetResponse - The request was aborted: Could not create SSL/TLS secure channel.
发布于 2014-06-19 15:02:06
我们找到了一个解决办法,但并不特别优雅。当我们连接到的服务器被负载平衡配置替换时,问题就开始发生了。如果我在客户端机器上编辑hosts
文件以直接与服务器对话,而不是通过负载平衡器,它就能工作。
此外,我还验证了这个答案中的代码更改也能工作。很高兴知道SSL/TLS的托管实现和非托管实现之间的区别.
https://stackoverflow.com/questions/24291053
复制相似问题