CodeXchange Tuesday, March 19, 2019
What's it?
My Snippets
Add Snippet
Contact Us

Website hosted by

Code Snippet Preview

Review the code snippet before inserting it on your project.

Snippet Metadata
Summary: Make your client overlook the certificate name mismatch programmatically. Little variation on code by Ted Graham and msdn. The class must be assigned to System.Net.ServicePointManager.CertificatePolicy in the beginning of client code.
Language: C#
Author: Isabelle Therrien
Author snippets RSS:
Culture: fr-CA
Bytes: 1518
Visual Studio 2005 Snippet:

Snippet Stats
Downloads: 4
Overall rating : 3
Average rating : Snippet rating

Snippet Preview
   public class MyPolicy: ICertificatePolicy
      enum CertificateProblem : long
         CertEXPIRED                   = 2148204801,
         CertVALIDITYPERIODNESTING     = 2148204802,
         CertROLE                      = 2148204803,
         CertPATHLENCONST              = 2148204804,
         CertCRITICAL                  = 2148204805,
         CertPURPOSE                   = 2148204806,
         CertISSUERCHAINING            = 2148204807,
         CertMALFORMED                 = 2148204808,
         CertUNTRUSTEDROOT             = 2148204809,
         CertCHAINING                  = 2148204810,
         CertREVOKED                   = 2148204812,
         CertUNTRUSTEDTESTROOT         = 2148204813,
         CertREVOCATION_FAILURE        = 2148204814,
         CertCN_NO_MATCH               = 2148204815,
         CertWRONG_USAGE               = 2148204816,
         CertUNTRUSTEDCA               = 2148204818
      /// Implement CheckValidationResult to ignore problems that 
      /// we are willing to accept. In this case, all those concerning Certificates.
      public bool CheckValidationResult(ServicePoint sp, X509Certificate cert,
         WebRequest request, int problem)
         foreach (CertificateProblem problemCode in Enum.GetValues(typeof(CertificateProblem)))
            int Certificate = unchecked( (int) problemCode);
            if ( problem == Certificate ) // only accept server name failed match
               return true;
         // The 1.1 framework calls this method with a problem of 0, even if nothing is wrong
         return (problem == 0);         

Snippet Comments
No comments for this snippet

Other snippets that may interest you..
Related Snippets
TDT - GridPage - Page_Init (C#)
CustomValitaor (C#)
Get the file extension from a file path or file name (VB.NET)
grab record from db and subtracts it from variable (VB.NET)

Copyright ©2009-2019 CodeXchange. Server version 1.0.3720.32855 Client Version

With from Barcelona

Most Helpful members
These are the members who have received the most points for their helpful samples
Zepho Zep
Robert Wagner
Galen Taylor

All time 'Hall of fame'
Formating a file size and adding the B, KB, MB and GB extension appropriately with string.Format (C#)
INI File Access (VB.NET)
Read XML from string into DataSet (C#)
Create Manifest File for your Application (VB.NET)
Round function to avoid banker's rounding (VB.NET)
Get Short and Long Path Names (VB.NET)
Sending Mail through authenticated SMTP server (C#)
One Way Hash for strings (C#)
Formating a file size and adding the B, KB, MB and GB extension appropriately with string.Format (C#)
How do I load an image from a URI address? (VB.NET)
Use our easy to use Visual Studio.NET addin client and start sharing code snippets with the CodeXchange community!
Refreshed: Tuesday, March 19, 2019