ServicePointManager.ServerCertificateValidationCallback
-
Dear Friends, I stuck at a point, to download a file from HTTPS site. I have a secured web site https/www.mySite.com/. I havent any idea which Certificate that server is using. I just want to down load a file from that site. For that I have written the code:
private static bool ValidateRemoteCertificate( object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors policyErrors ) { if (policyErrors == SslPolicyErrors.None) return true; else return false; )); // // Do not allow this client to communicate with unauthenticated servers. // return false; // }
but it always shows the error "System.Net.Security.SslPolicyErrors.RemoteCertificateNameMismatch" and if i forcefully return true it works fine... what is proper solution?????? thnaks in advance -
Dear Friends, I stuck at a point, to download a file from HTTPS site. I have a secured web site https/www.mySite.com/. I havent any idea which Certificate that server is using. I just want to down load a file from that site. For that I have written the code:
private static bool ValidateRemoteCertificate( object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors policyErrors ) { if (policyErrors == SslPolicyErrors.None) return true; else return false; )); // // Do not allow this client to communicate with unauthenticated servers. // return false; // }
but it always shows the error "System.Net.Security.SslPolicyErrors.RemoteCertificateNameMismatch" and if i forcefully return true it works fine... what is proper solution?????? thnaks in advanceIf you are happy to disable the checking of the certificate (not recommended) then use something like
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(
delegate
{
return true;
});If you are using a WebClient for instance, it should go just before you do the call that will connect (i.e. client.UploadFile(), client.UploadValues(), etc)