1 class PermissiveCertificatePolicy 2 { 3 string subjectName; 4 static PermissiveCertificatePolicy currentPolicy; 5 PermissiveCertificatePolicy(string subjectName) 6 { 7 this.subjectName = subjectName; 8 ServicePointManager.ServerCertificateValidationCallback += 9 new System.Net.Security.RemoteCertificateValidationCallback(RemoteCertValidate); 10 } 11 12 public static void Enact(string subjectName) 13 { 14 currentPolicy = new PermissiveCertificatePolicy(subjectName); 15 } 16 17 bool RemoteCertValidate(object sender, X509Certificate cert, X509Chain chain, System.Net.Security.SslPolicyErrors error) 18 { 19 20 if (cert.Subject == subjectName) 21 { 22 return true; 23 } 24 25 return false; 26 } 27 } 28 29 ----------------调用---------------- 30 31 PermissiveCertificatePolicy.Enact("CN=WIN-85QBE2LGCIQ"); 32 33