ServicePointManager.CertificatePolicy Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Note: This API is now obsolete.

Gets or sets policy for server certificates.

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

[ObsoleteAttribute("CertificatePolicy is obsoleted for this type, please use ServerCertificateValidationCallback instead.")]
public static ICertificatePolicy CertificatePolicy { get; set; }

Property Value

Type: System.Net.ICertificatePolicy

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 = new MyCertificatePolicy();

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


To set the CertificatePolicy property. Associated enumeration: SecurityPermissionFlag.UnmanagedCode

.NET Framework
Available since 1.1
Return to top