HTTPS and trusting server certificates

If you making HttpWebRequest calls to secure servers, using HTTPS you’ll probably come across a situation where the server request fails. There can be a number of reasons for this – sometimes you might be using a test certificate which has no trusted root, or your using your own certificate authority which isn’t in the trusted root certificate store on the PC you’re running the tests from. Well you can override the policy, to accept specific certificates, or a blanket cover-all to accept all certificates.

For more information see the MSDN Library page.

Place this somewhere before you start making HttpWebRequest jobs, and define the class.

Then define this class. You can change the CheckValidationResult function to check for different problems, such as expired certificates, untrusted certificate authority etc. Return true if you want to trust the certificate, and false if you don’t want to.

2 Replies to “HTTPS and trusting server certificates”

  1. Hi,
    This article is really informative. Thanks for the valuable piece of information.
    I need some more info : I did exactly what you have specified. Now I am getting a different error – Unable to create transport creation. Any idea whats happening?

    Thanks in advance

  2. Can’t find any help on google with that error message. Is it intermittent? Make sure you are closing the response each time. Can you tell me the exact error message?

Comments are closed.