<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>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. </Title>
      <Shortcut>Makeyourclientoverlookthecertificatenamemismatchprogrammatically.LittlevariationoncodebyTedGrahamandmsdn.TheclassmustbeassignedtoSystem.Net.ServicePointManager.CertificatePolicyinthebeginningofclientcode.</Shortcut>
      <Description>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.  [C#]</Description>
      <Author>Isabelle Therrien</Author>
      <HelpUrl>/PreviewSnippet.aspx?SnippetID=d40708fc-4041-42b8-9016-f0ac96d14fce</HelpUrl>
      <SnippetTypes>
        <SnippetType>SurroundsWith</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Code Language="csharp"><![CDATA[	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
		}
		
		/// <summary>
		/// Implement CheckValidationResult to ignore problems that 
		/// we are willing to accept. In this case, all those concerning Certificates.
		/// </summary>
		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);         
		} 
	}
]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>