How do you get a System.Web.HttpWebRequest object to use SSL 2.0?

16,942

I've hit this issue myself when dealing with Ssl3, though I'm not sure if the same advice would work for SSL2?

To work around the issue I set the Ssl3 flag on the security protocol like so:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

Check out these links for more details:

system.net.servicepointmanager.securityprotocol on MSDN

security protocol enumeration on MSDN

They might point you in the right direction if you're lucky :)

Share:
16,942
Dylan Bennett
Author by

Dylan Bennett

There's nobody else like me. I checked. secretGeek wrote: "currently stack overflow suffers from too many great people ready to answer questions -- not enough 'unwashed masses' asking" One unwashed mass at your service. I've got tons of unwashed questions.

Updated on June 20, 2022

Comments

  • Dylan Bennett
    Dylan Bennett almost 2 years

    I don't know if I have all the information needed to phrase this question well, so bear with me.

    I have a local web page (local meaning 192.168.*) that is protected with a self-signed SSL cert. I'm trying to access this page using a System.Net.HttpWebRequest object, but I'm running into a weird problem.

    If this page is accessed in Internet Explorer with the "Use SSL 2.0" option turned off, the browser returns back an error as if it can't establish a connection. (In other words, a browser connection error, as opposed to a server-sent error.) If the "Use SSL 2.0" option is turned on, the page works fine and you get the standard warning that this is a self-signed cert, do you want to continue, etc. (Oddly enough, Firefox, which supposedly does not have SSL 2.0 turned on, works just fine.)

    Now my problem is that I'm trying to access this page with an HttpWebRequest object and the error it's returning back is that the connection has been unexpectedly closed, just like the error IE throws when "Use SSL 2.0" is turned off. (I already have code in place to ignore the fact that it's a self-signed cert, but it's not even getting that far.)

    How do I get the System.Net.HttpWebRequest to, well, "Use SSL 2.0" when it's making its request?

  • Dylan Bennett
    Dylan Bennett over 15 years
    That was it! As soon as I set it explicitly to SSL3, it worked. Thanks!
  • barthoda
    barthoda over 11 years
    Thanks so much. Using System.Diagnostics to turn tracing on for System.Net gave me these logs 'System.Net Information: 0 : [16212] InitializeSecurityContext(In-Buffers count=2, Out-Buffer length=0, returned code=AlgorithmMismatch). System.Net Error: 0 : [16212] Exception in HttpWebRequest#49844091:: - The request was aborted: Could not create SSL/TLS secure channel.. System.Net Error: 0 : [16212] Exception in HttpWebRequest#49844091::GetResponse - The request was aborted: Could not create SSL/TLS secure channel.. '
  • AFract
    AFract over 10 years
    Setting SecurityProtocol seems also to be a good fix to this tricky issue : blogs.msdn.com/b/fiddler/archive/2012/03/29/… which I'm currently experiencing.
  • EricLaw
    EricLaw over 9 years
    FWIW, "AlgorithmMismatch" means the server is probably hitting this: blogs.msdn.com/b/ieinternals/archive/2009/12/08/…