ServicePointManager.CertificatePolicy ServicePointManager.CertificatePolicy ServicePointManager.CertificatePolicy ServicePointManager.CertificatePolicy Property

Définition

Avertissement

Cette API est désormais obsolète.

Obtient ou définit la stratégie pour les certificats serveur.Gets or sets policy for server certificates.

public:
 static property System::Net::ICertificatePolicy ^ CertificatePolicy { System::Net::ICertificatePolicy ^ get(); void set(System::Net::ICertificatePolicy ^ value); };
[System.Obsolete("Use ServerCertificateValidationCallback instead", false)]
[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; }
member this.CertificatePolicy : System.Net.ICertificatePolicy with get, set
Public Shared Property CertificatePolicy As ICertificatePolicy

Valeur de propriété

Objet qui implémente l'interface ICertificatePolicy.An object that implements the ICertificatePolicy interface.

Exemples

L’exemple de code suivant montre comment intercepter une exception de stratégie de certificat pour une stratégie de certificat personnalisée.The following code example shows how to catch a certificate policy exception for a custom certificate policy. Il part du principe que l’objet de stratégie de certificat a été défini, que le Uniform Resource Identifier (Uri) de la ressource Web est contenu myUridans la variable, et qu’il existe ProcessResponse une méthode nommée qui effectue le travail de l’application.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.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 = 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

Remarques

Lorsque la CertificatePolicy propriété est définie sur un ICertificatePolicy objet d’interface, ServicePointManager l’objet utilise la stratégie de certificat définie dans cette instance au lieu de la stratégie de certificat par défaut.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.

La stratégie de certificat par défaut autorise des certificats valides et des certificats valides qui ont expiré.The default certificate policy allows valid certificates and valid certificates that have expired.

Sécurité

SecurityPermission
Pour définir la CertificatePolicy propriété.To set the CertificatePolicy property. Énumération associée:UnmanagedCodeAssociated enumeration: UnmanagedCode

S’applique à

Voir aussi