webclient downloading content files from an https ssl

Monday, October 05, 2009 4:09 AM | Leave a reply »

i was using the webclient object to download files from a website and my application worked fine. my client decided to add an SSL certeficate to the website and has required me to change my code to request the file through https instead of http

all i had to do was change the URL to have https:// instead of http://

but when i first tried the code. i got this exception:

System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.

 

after doing a little research i found out that this error can not be fixed on the development environment.

 

this is because one of the following issues is occuring

  1. The certificate cannot be found for any reason
  2. One of issuers in the chain cannot be validated successfully
  3. The name of the certificate is invalid or does not match the name of the site.

source

now what i had to do is write a piece of code that ignores the SSL errors when the application is in the development environment.

 

ServicePointManager.ServerCertificateValidationCallback +=
 new System.Net.Security.RemoteCertificateValidationCallback
(bypassSSLErrors);
// now this is only static code needs to execute once 
private static bool bypassSSLErrors(object sender,
           X509Certificate cert, X509Chain chain, 
           System.Net.Security.SslPolicyErrors error)
           {
              return true;
           }


Comments

  1. Gravatar Anonymous says:

    Re : # 

    You've been kicked (a good thing) - Trackback from DotNetKicks.com


Leave a Reply



 

Please add 7 and 4 and type the answer here: