.NET Framework Developer Center > .NET Development Forums > .NET Framework Networking and Communication > SSL: "An existing connection was forcibly closed by the remote host."
Ask a questionAsk a question
 

AnswerSSL: "An existing connection was forcibly closed by the remote host."

  • Sunday, April 09, 2006 12:45 PMSiostra Andzelika Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello,
    I'm trying to do a secure connect to the site https://212.77.100.18/p/ with .net 2.0 HttpWebRequest class,
    unfortunately for some reason I'm not able to do that - WebException is thrown with inner exception message of "An existing connection was forcibly closed by the remote host."

    I hoped I'll solve my problem with RemoteCertificateValidationCallback delegate which always returns "true", but it isn't called at all for this site (but works for other sites which needs manual acceptance of certificate).

    The HttpWebResponse should return "403 Forbidden" as in Internet Explorer.

    Can you help me, please?

    //my code below

                        ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(ValidateServerCertificate);

                        HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://212.77.100.18/p/");
                        req.Method = "GET";
                        req.AllowAutoRedirect = false;
                        req.CookieContainer = new CookieContainer();
                        req.KeepAlive = true;
                        req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0; .NET CLR 2.0.50727)";
                        req.ContentType = "application/x-www-form-urlencoded";
                        req.Accept = "*/*";
                       /*
    I have also tried this:                                            req.ClientCertificates.Add(X509Certificate.CreateFromCertFile("chris.cer"));
                          */                                       
                        using (HttpWebResponse res = (HttpWebResponse)req.GetResponse())
                        {
                            //not reached
                        }

    public static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
            {
    return true;
    }

Answers

  • Thursday, April 13, 2006 2:05 AMMariya Atanasova [NCL]MSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    For this particular server you'll have to set the protocol to ssl3.

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

    I verified this fixes your problem and you will now get the 403 error as expected. The problem is a server problem, it drops the connection when we are trying to negotiate the ssl connection.

    Let me know if this helped

    Mariya

  • Thursday, April 13, 2006 7:17 AMSiostra Andzelika Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    yes! thank you very much

    <bucket of roses>

All Replies