Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. ServicePointManager.ServerCertificateValidationCallback

ServicePointManager.ServerCertificateValidationCallback

Scheduled Pinned Locked Moved C#
helpquestioncsharpcomsysadmin
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    himuskanhere
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • H himuskanhere

      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

      J Offline
      J Offline
      jo H
      wrote on last edited by
      #2

      If 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)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups