Search code examples
c#ssl-certificatewebclient.uploaddata

C# remote web request certificate error


I am getting the following error when trying to perform a HttpWebRequest to a remote server over SSL (the url is https://sandbox.payfast.co.za):

"The remote certificate is invalid according to the validation procedure"

The certificate seems to be valid and I can successfully make a web request to another url.

Could someone tell me how the .NET validates the certificate and how I can find out the exact problem with the certificate.

To try and bypass this I added:

        ServicePointManager.ServerCertificateValidationCallback 
        = (obj, certificate, chain, errors) => true;

But it seems this will not work in medium trust.

Any help appreciated.

Thanks Ben


Solution

  • After testing testing a few requests to other url's we switched back to the one originally raising the certificate validation exception and it worked!

    Both parties ensure me nothing was changed.

    Either way, I found this post useful in trying to diagnose the problem further http://blogs.msdn.com/jpsanders/archive/2009/09/16/troubleshooting-asp-net-the-remote-certificate-is-invalid-according-to-the-validation-procedure.aspx