Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7177197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:39:45+00:00 2026-05-28T16:39:45+00:00

I’m using the following code to accept bad server certificates: ServicePointManager.ServerCertificateValidationCallback = delegate(object s,

  • 0

I’m using the following code to accept bad server certificates:

ServicePointManager.ServerCertificateValidationCallback = delegate(object s,
  X509Certificate cert, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
    Debug.WriteLine("Returned certificate valid");
    return true;
}

And this code to make a request:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://localhost/test");
req.Timeout = 5000;
try {
    Debug.WriteLine("Checking...");
    HttpWebResponse response = (HttpWebResponse)req.GetResponse();
    Debug.WriteLine("Done");
}
catch
{
    Debug.WriteLine("Error");
    //error
}

The first time I run this request it waits 5 seconds and then throws a timeout exception. The validation callback is executed successfully right before the timeout, and I can see that the correct (invalid) certificate is passed in.

If I increase the timeout to 15 seconds, it takes 15 seconds for the callback to be executed and then the request times out.

Subsequent requests (without restarting the program) have a success rate of about 90%. (10% of them timeout; the others return almost instantly.) What is going on here?

EDIT: If I unplug my network connection all the requests return successfully which makes me think it must be trying to contact a CA or something… Why does it timeout instead of throwing a security exception and how can I stop this?

EDIT 2: I commented out the timeout @ScottSmith’s suggestion and all the requests now succeed! Sometimes they succeed before the old timeout period which is really confusing me. Is there any way I can get .net to stop trying to validate the certificate behind the scenes?

EDIT 3: I found a forum post that I think explains my problem. Look at the final post on this page: http://www.pcreview.co.uk/forums/ie-going-very-slow-if-certificate-isnt-valid-t735059.html I used wireshark and once the request is issued, 3 DNS queries for http://www.download.windowsupdate.com are made. Once they fail (since the computer is not connected to the internet) the certificate validation callback is finally called and the request completes. If anyone can come up with a way to disable this behavior that would be amazing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:39:46+00:00Added an answer on May 28, 2026 at 4:39 pm

    It is hard to tell what’s wrong but some things to check:

    • set ServicePointManager.CheckCertificateRevocationList explicitly to false after you add your handler (it default to false but might somehow be true in your case)

    • check tha value of sslPolicyErrors in your callback, perhaps it gives you some clue on what is going on

    • check the properties of req.ServicePoint, it might help narrow down what is going on (esp. to see if your request is being redirected)

    • check your proxy settings, they might be part of the problem

    • is there lots of TCP/IP traffic going on ? (check with netstat, see whether you have several TIME_WAIT sockets)

    • what happens when try that URL from a browser ?

    • check the logs on the web server (IIS?) for anything regarding the http request

    UPDATE – after EDIT from OP:

    you could try to set ServicePointManager.DnsRefreshTimeout to a very high value and see if that helps BUT be aware that this might have other negative effects!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i got an object with contents of html markup in it, for example: string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.