The underlying connection was closed An unexpected error occurred on a send With SSL Certificate

0 votes

I get this exception and that is the issue:-

The underlying connection was closed: An unexpected error occurred on a send.


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 a comprehensive dashboard. Everything works fine with all the other elements of the website except with one of our e-mail marketing components which we are using as an iframe solution within our dashboard. The way it works is, I send a HttpWebRequest object 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-4 hours), and then from the call to

webRequest.GetResponse();
I get the exception

The underlying connection was closed: An unexpected error occurred on a send.

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

  • anything is edited in web.config.

I am really exhausted from all the options that I could think of. Any leads will be beneficial!!

I tried explicitly adding:-

  • 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 somehow. Any direction toward resolution is greatly appreciated.

Code mentioned below:-

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
Feb 18 in Others by Aditya
• 7,280 points
544 views

1 answer to this question.

0 votes

The solution for this for me was by using tls12:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

answered Feb 18 by Rahul
• 8,980 points

Related Questions In Others

0 votes
0 answers

The page cannot be displayed because an internal server error has occurred on server

When  I've deployed the website I installed  ...READ MORE

May 23 in Others by Kichu
• 19,040 points
71 views
0 votes
1 answer

Error waiting for a debug connection: The log reader stopped unexpectedly

Hi@akhtar, You need to add textDirection in your ...READ MORE

answered Jul 23, 2020 in Others by MD
• 95,360 points
1,599 views
0 votes
1 answer

Error waiting for a debug connection: The log reader stopped unexpectedly

Hi@akhtar, You need to execute flutter clean command in your project ...READ MORE

answered Jul 24, 2020 in Others by MD
• 95,360 points
2,911 views
0 votes
1 answer

Connection in Hbase

Following code is used to open a ...READ MORE

answered Jul 11, 2018 in Database by Data_Nerd
• 2,390 points
225 views
0 votes
1 answer

Connection Mongos check - MongoDB

The following command needs to be used ...READ MORE

answered Aug 3, 2018 in Database by kurt_cobain
• 9,390 points
346 views
0 votes
1 answer

Coinbase spot price SSL Error: does not support SSL at Request

Add 'strictSSL': false to the new client: var btcClient = ...READ MORE

answered Sep 6, 2018 in Blockchain by digger
• 26,720 points
338 views
0 votes
1 answer

Forcing ssl for Kubernetes Ingress on GKE

https://github.com/kubernetes/ingress-gce#frontend-https If you want to block http, you ...READ MORE

answered Sep 6, 2018 in Kubernetes by ajs3033
• 7,280 points
3,486 views
0 votes
1 answer

It shows black screen when trying to load Map on device with ionic 2 Google Map Native plugin

In order to answer your question, start ...READ MORE

answered Feb 8 in Others by Rahul
• 8,980 points
153 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP