ServicePointManager.CertificatePolicy Property

Definition

Caution

CertificatePolicy is obsoleted for this type, please use ServerCertificateValidationCallback instead. http://go.microsoft.com/fwlink/?linkid=14202

Gets or sets policy for server certificates.

C#
public static System.Net.ICertificatePolicy CertificatePolicy { get; set; }
C#
[System.Obsolete("CertificatePolicy is obsoleted for this type, please use ServerCertificateValidationCallback instead. http://go.microsoft.com/fwlink/?linkid=14202")]
public static System.Net.ICertificatePolicy CertificatePolicy { get; set; }

Property Value

An object that implements the ICertificatePolicy interface.

Attributes

Examples

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.

C#
ServicePointManager.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.Status == WebExceptionStatus.TrustFailure)
    {
        // Code for handling security certificate problems goes here.
    }
    // Other exception handling goes here
}

Remarks

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.

Applies to

Product Versions (Obsolete)
.NET Framework 1.1 (2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1)

See also