I have searched many places and found the following answers on a foreign website to share with you:
Http://www.tech-archive.net/Archive/DotNet/microsoft.public.dotnet.framework.aspnet/2006-03/msg02317.html
[Open this link in a new window]
// NET 1.0/1.1 version:
// ======================================
Using System. net;
Using System. Security. cryptography. x509certificates;
/**/ ///
///You can call this method before using webrequest to connect.
///
Private Void Methodtoaccessssl ()
{
//
Servicepointmanager. certificatepolicy= NewAcceptallcertificatepolicy ();
//Webrequest myrequest = webrequest. Create (URL );
}
Internal Class Acceptallcertificatepolicy: icertificatepolicy
{
Public Acceptallcertificatepolicy () {}
Public Bool Checkvalidationresult (servicepoint spoint,
X509certificate cert, webrequest wrequest, Int Certprob)
{
Return True;
}
}
// NET 2.0 version
// ======================
Using System. net;
Using System. Security. cryptography. x509certificates;
Using System. net. Security;
/**/ ///
///You can call this method before using webrequest to connect.
///
Private Void Methodtoaccessssl ()
{
//
Servicepointmanager. servercertificatevalidationcallback=
NewRemotecertificatevalidationcallback (validateservercertificate );
//Webrequest myrequest = webrequest. Create (URL );
}
// The following method is invoked by the remotecertificatevalidationdelegate.
Public Static Bool Validateservercertificate (
Object Sender,
X509certificate certificate,
X509chain chain,
Sslpolicyerrors)
{
If (Sslpolicyerrors = Sslpolicyerrors. None)
Return True ;
Console. writeline ( " Certificate error: {0} " , Sslpolicyerrors );
// Do not allow this client to communicate with unauthenticated servers.
Return False ;
}