下面的连接已关闭:发送时发生意外错误:使用SSL证书 [英] THE UNDERLYING CONNECTION WAS CLOSED: AN UNEXPECTED ERROR OCCURRED ON A SEND : With SSL Certificate

查看:403
本文介绍了下面的连接已关闭:发送时发生意外错误:使用SSL证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:我的日志中出现了下面的连接已关闭:发送时发生意外错误的异常,并且它在我们的电子邮件营销系统中打破了我们的OEM集成,随机时间从[1小时 - 4小时]



我的网站托管在Windows Server 2008 R2与IIS 7.5.7600。这个网站有大量的OEM组件和综合仪表板。一切正常与网站的所有其他元素,除了我们的电子邮件营销组件之一,我们在我们的仪表板中使用作为iframe解决方案。它的工作原理是,我发送一个httpWebRequestobject所有的凭据,我得到一个url,我放在一个iframe,它的工作原理。但它只工作一段时间[1小时 - 4小时],然后我得到以下异常下面的连接已关闭:发送时发生意外错误,即使系统尝试从httpWebRequest获取URL失败,具有相同的异常。使它再次工作的唯一方法是回收应用程序池或在web.config中编辑的任何内容。



尝试的选项



显式添加, keep-alive = false



keep-alive = true / p>

增加超时时间:< httpRuntime maxRequestLength =2097151executionTimeout =9999999enable =truerequestValidationMode =2.0/> ;



我已将此页面上传到非SSL网站,以检查生产服务器上的SSL证书是否正在建立连接,如何。



非常感谢任何解决方案。



代码:

 公共函数CreateHttpRequestJson(ByVal url)As String 
Try
Dim result As String = String.Empty
Dim httpWebRequest = DirectCast (WebRequest.Create(https://api.xxxxxxxxxxx.com/api/v3/externalsession.json),HttpWebRequest)
httpWebRequest.ContentType =text / json
httpWebRequest.Method = PUT
httpWebRequest.ContentType =application / x-www-form-urlencoded
httpWebRequest.KeepAlive = False
'ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3

'TODO将integratorID更改为serviceproviders帐户ID,useremail
使用streamWriter =新的StreamWriter(httpWebRequest.GetRequestStream())
Dim json As String =新的JavaScriptSerializer $ b Key .Email = useremail,_
Key .Chrome =None,_
Key .Url = url,_
Key .IntegratorID = userIntegratorID,_
。 ClientID = clientIdGlobal _
})

'TODO将其移动到web.config,以下API密钥是holonis帐户API密钥
SetBasicAuthHeader(httpWebRequest,holonisApiKey,)
streamWriter.Write(json)
streamWriter.Flush()
streamWriter.Close()

Dim httpResponse = DirectCast(httpWebRequest.GetResponse(),HttpWebResponse)
使用streamReader =新的StreamReader(httpResponse.GetResponseStream())
result = streamReader.ReadToEnd()
result = result.Split(New [Char](){:})
result =https:& result.Substring(0,result.Length - 2)
结束使用
结束使用
Me.midFrame.Attributes(src)= result
Catch ex As Exception
objLog.WriteLog(Error:& ex.Message)
如果(ex.Message.ToString()。包含(无效的电子邮件))然后
'TODO在UI $上显示消息b $ b ElseIf(ex.Message.ToString()。Contains(Email Taken))然后
'TODO在UI
上显示消息ElseIf(ex.Message.ToString()。Contains访问级别))然后
'TODO在UI
上显示消息ElseIf(ex.Message.ToString()。包含(不安全的密码))然后
'TODO在UI $上显示消息b $ b ElseIf(ex.Message.ToString()。Contains(Invalid Password))然后
'TODO在UI
上显示消息ElseIf(ex.Message.ToString Person Name))然后
'TODO在UI上显示消息
结束如果
结束尝试
结束函数


Public Sub SetBasicAuthHeader ByVal请求作为WebRequest,ByVal userName As [String],ByVal userPassword As [String])
Dim authInfo As String = Convert.ToString(userName)& :& Convert.ToString(userPassword)
authInfo = Convert.ToBase64String(Encoding。[Default] .GetBytes(authInfo))
request.Headers(Authorization)=Basic& authInfo
End Sub`


解决方案

是tls12:

  ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; 


Issue : I get this exception "THE UNDERLYING CONNECTION WAS CLOSED: AN UNEXPECTED ERROR OCCURRED ON A SEND" in my logs and it is breaking our OEM integration with our email marketing system at random times varying from [1hour - 4 hours]

My website is hosted on a windows server 2008 R2 with IIS 7.5.7600. This website has a large number of OEM components and comprehensive dashboard. Everything works fine with all the other elements of the website except with one of our email marketing component which we are using as an iframe solution within our dashboard. The way it works is, I send a httpWebRequestobject with all the credentials and i get a url back which i put in an iframe and it works. But it only works for some time [1 hour - 4 hours ]and then i get the below exception "THE UNDERLYING CONNECTION WAS CLOSED: AN UNEXPECTED ERROR OCCURRED ON A SEND" and even if the system tries to get the URL from the httpWebRequest it fails with the same exception. The only way to make it work again is to recycle the application pool or anything is edited in web.config. I am really exhausted all the option that i could think of.

Option tried

Explicitly added, keep-alive = false

keep-alive = true

Increased the time out : <httpRuntime maxRequestLength="2097151" executionTimeout="9999999" enable="true" requestValidationMode="2.0" />

I have uploaded this page to a non SSL website to check if the SSL certificate on our production server is making the connection to drop some how.

Any direction toward resolution is greatly appreciated.

Code :

Public Function CreateHttpRequestJson(ByVal url) As String
    Try
        Dim result As String = String.Empty
        Dim httpWebRequest = DirectCast(WebRequest.Create("https://api.xxxxxxxxxxx.com/api/v3/externalsession.json"), HttpWebRequest)
        httpWebRequest.ContentType = "text/json"
        httpWebRequest.Method = "PUT"
        httpWebRequest.ContentType = "application/x-www-form-urlencoded"
        httpWebRequest.KeepAlive = False
        'ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3

        'TODO change the integratorID to the serviceproviders account Id, useremail 
        Using streamWriter = New StreamWriter(httpWebRequest.GetRequestStream())
            Dim json As String = New JavaScriptSerializer().Serialize(New With { _
            Key .Email = useremail, _
            Key .Chrome = "None", _
            Key .Url = url, _
            Key .IntegratorID = userIntegratorID, _
            Key .ClientID = clientIdGlobal _
            })

            'TODO move it to the web.config, Following API Key is holonis accounts API Key
            SetBasicAuthHeader(httpWebRequest, holonisApiKey, "")
            streamWriter.Write(json)
            streamWriter.Flush()
            streamWriter.Close()

            Dim httpResponse = DirectCast(httpWebRequest.GetResponse(), HttpWebResponse)
            Using streamReader = New StreamReader(httpResponse.GetResponseStream())
                result = streamReader.ReadToEnd()
                result = result.Split(New [Char]() {":"})(2)
                result = "https:" & result.Substring(0, result.Length - 2)
            End Using
        End Using
        Me.midFrame.Attributes("src") = result
    Catch ex As Exception
        objLog.WriteLog("Error:" & ex.Message)
        If (ex.Message.ToString().Contains("Invalid Email")) Then
            'TODO Show message on UI
        ElseIf (ex.Message.ToString().Contains("Email Taken")) Then
            'TODO Show message on UI
        ElseIf (ex.Message.ToString().Contains("Invalid Access Level")) Then
            'TODO Show message on UI
        ElseIf (ex.Message.ToString().Contains("Unsafe Password")) Then
            'TODO Show message on UI
        ElseIf (ex.Message.ToString().Contains("Invalid Password")) Then
            'TODO Show message on UI
        ElseIf (ex.Message.ToString().Contains("Empty Person Name")) Then
            'TODO Show message on UI
        End If
    End Try
End Function


Public Sub SetBasicAuthHeader(ByVal request As WebRequest, ByVal userName As [String], ByVal userPassword As [String])
    Dim authInfo As String = Convert.ToString(userName) & ":" & Convert.ToString(userPassword)
    authInfo = Convert.ToBase64String(Encoding.[Default].GetBytes(authInfo))
    request.Headers("Authorization") = "Basic " & authInfo
End Sub`

解决方案

For me it was tls12:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

这篇关于下面的连接已关闭:发送时发生意外错误:使用SSL证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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