Skip to main content
.NET Framework Class Library
ServicePointManager..::.CertificatePolicy Property

Note: This API is now obsolete.

Gets or sets policy for server certificates.

Namespace: System.Net
Assembly: System (in System.dll)
Syntax
<ObsoleteAttribute("CertificatePolicy is obsoleted for this type, please use ServerCertificateValidationCallback instead. http://go.microsoft.com/fwlink/?linkid=14202")> _
Public Shared Property CertificatePolicy As ICertificatePolicy
[ObsoleteAttribute("CertificatePolicy is obsoleted for this type, please use ServerCertificateValidationCallback instead. http://go.microsoft.com/fwlink/?linkid=14202")]
public static ICertificatePolicy CertificatePolicy { get; set; }
[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);
}
[<ObsoleteAttribute("CertificatePolicy is obsoleted for this type, please use ServerCertificateValidationCallback instead. http://go.microsoft.com/fwlink/?linkid=14202")>]
static member CertificatePolicy : ICertificatePolicy with get, set

Property Value

Type: System.Net..::.ICertificatePolicy
An object that implements the ICertificatePolicy interface.
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.

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.


 ServicePointManager.CertificatePolicy = New MyCertificatePolicy()

 ' Create the request and receive the response
 Try
     Dim myRequest As WebRequest = WebRequest.Create(myUri)
     Dim myResponse As WebResponse = myRequest.GetResponse()

     ProcessResponse(myResponse)

     myResponse.Close()

 ' Catch any exceptions
 Catch e As WebException
     If e.Status = WebExceptionStatus.TrustFailure Then
         ' Code for handling security certificate problems goes here.
     End If
     ' Other exception handling goes here
  End Try



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
       }
   


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
}

Version Information

.NET Framework

Supported in: 1.1, 1.0
Obsolete (compiler warning) in 4
Obsolete (compiler warning) in 3.5
Obsolete (compiler warning) in 3.5 SP1
Obsolete (compiler warning) in 3.0
Obsolete (compiler warning) in 3.0 SP1
Obsolete (compiler warning) in 3.0 SP2
Obsolete (compiler warning) in 2.0
Obsolete (compiler warning) in 2.0 SP1
Obsolete (compiler warning) in 2.0 SP2

.NET Framework Client Profile

Obsolete (compiler warning) in 4
Obsolete (compiler warning) in 3.5 SP1
.NET Framework Security
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.