Export (0) Print
Expand All

ServicePointManager.CertificatePolicy Property

NOTE: This property is now obsolete.

Gets or sets policy for server certificates.

Namespace: System.Net
Assembly: System (in system.dll)

[ObsoleteAttribute(L"CertificatePolicy is obsoleted for this type, please use ServerCertificateValidationCallback instead. http://go.microsoft.com/fwlink/?linkid=14202")] 
public:
static property ICertificatePolicy^ CertificatePolicy {
	ICertificatePolicy^ get ();
	void set (ICertificatePolicy^ value);
}
/** @property */
public static ICertificatePolicy get_CertificatePolicy ()

/** @property */
public static void set_CertificatePolicy (ICertificatePolicy value)

public static function get CertificatePolicy () : ICertificatePolicy

public static function set CertificatePolicy (value : ICertificatePolicy)

Not applicable.

Property Value

An object that implements the ICertificatePolicy interface.

When the CertificatePolicy property is set to an ICertificatePolicy interface object, the ServicePointManager object uses the certificate policy defined in that instance instead of the default certificate policy.

The default certificate policy allows valid certificates and valid certificates that have expired.

The following code example shows how to catch a certificate policy exception for a custom certificate policy. It assumes that the certificate policy object has been defined, that the Uniform Resource Identifier (URI) for the Web resource is contained in the variable myUri, and that there is a method named ProcessResponse that performs the work of the application.

ServicePointManager::CertificatePolicy = gcnew MyCertificatePolicy;

// Create the request and receive the response
try
{
   WebRequest^ myRequest = WebRequest::Create( myUri );
   WebResponse^ myResponse = myRequest->GetResponse();
   ProcessResponse( myResponse );
   myResponse->Close();
}
// Catch any exceptions
catch ( WebException^ e ) 
{
   if ( e->Status == WebExceptionStatus::TrustFailure )
   {
      // Code for handling security certificate problems goes here.
   }
   // Other exception handling goes here
}

ServicePointManager.set_CertificatePolicy(new MyCertificatePolicy());

// Create the request and receive the response
try {
    WebRequest myRequest = WebRequest.Create(myUri);
    WebResponse myResponse = myRequest.GetResponse();
    ProcessResponse(myResponse);
    myResponse.Close();
}
// Catch any exceptions
catch (WebException e) {
    if (e.get_Status() == WebExceptionStatus.TrustFailure) {
        // Code for handling security certificate problems goes here.
    }
    // Other exception handling goes here
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 1.0, 1.1, 2.0
Obsolete (compiler warning) in 3.0

.NET Compact Framework

Supported in: 1.0
Obsolete (compiler warning) in 2.0

Community Additions

ADD
Show:
© 2014 Microsoft