HttpListenerRequest.ClientCertificateError HttpListenerRequest.ClientCertificateError HttpListenerRequest.ClientCertificateError HttpListenerRequest.ClientCertificateError Property

Définition

Obtient un code d’erreur qui identifie un problème avec le X509Certificate fourni par le client.Gets an error code that identifies a problem with the X509Certificate provided by the client.

public:
 property int ClientCertificateError { int get(); };
public int ClientCertificateError { get; }
member this.ClientCertificateError : int
Public ReadOnly Property ClientCertificateError As Integer

Valeur de propriété

Un Int32 valeur contenant un code d’erreur Windows.An Int32 value that contains a Windows error code.

Exceptions

Le certificat client n'a pas encore été initialisé par un appel à la BeginGetClientCertificate(AsyncCallback, Object) ou GetClientCertificate() méthodesThe client certificate has not been initialized yet by a call to the BeginGetClientCertificate(AsyncCallback, Object) or GetClientCertificate() methods ou-or - L’opération est toujours en cours.The operation is still in progress.

Exemples

L’exemple de code suivant vérifie cette propriété pour déterminer si la demande comprend un certificat client valide.The following code example checks this property to determine whether the request includes a valid client certificate.

Console.WriteLine("Listening for {0} prefixes...", listener.Prefixes.Count);
HttpListenerContext context = listener.GetContext();
HttpListenerRequest request = context.Request;
Console.WriteLine("Received a request.");
// This server requires a valid client certificate
// for requests that are not sent from the local computer.

// Did the client omit the certificate or send an invalid certificate?
if (request.IsAuthenticated &&
    request.GetClientCertificate() == null || 
    request.ClientCertificateError != 0)
{
    // Send a 403 response.
    HttpListenerResponse badCertificateResponse = context.Response ;
    SendBadCertificateResponse(badCertificateResponse);
    Console.WriteLine("Client has invalid certificate.");
    continue;
}
Console.WriteLine("Listening for {0} prefixes...", listener.Prefixes.Count)
Dim context As HttpListenerContext = listener.GetContext()
Dim request As HttpListenerRequest = context.Request
Console.WriteLine("Received a request.")
' This server requires a valid client certificate
' for requests that are not sent from the local computer.

' Did the client omit the certificate or send an invalid certificate?
If request.IsAuthenticated AndAlso request.GetClientCertificate() Is Nothing OrElse request.ClientCertificateError <> 0 Then
    ' Send a 403 response.
    Dim badCertificateResponse As HttpListenerResponse = context.Response
    SendBadCertificateResponse(badCertificateResponse)
    Console.WriteLine("Client has invalid certificate.")
    Continue Do
End If

Remarques

Cette propriété contient un code d’erreur Windows retourné par la Secure Channel (Schannel) prise en charge Interface SSPI (Security Provider), qui est utilisé pour valider le certificat.This property contains a Windows error code returned by the Secure Channel (Schannel) Security Support Provider Interface (SSPI), which is used to validate the certificate. Pour plus d’informations sur la prise en charge SSPI pour Schannel, consultez « Création a Secure Connection à l’aide de Schannel » dans la documentation de sécurité à http://msdn.microsoft.com/library .For more information about SSPI support for Schannel, see "Creating a Secure Connection Using Schannel" in the Security documentation at http://msdn.microsoft.com/library.

S’applique à

Voir aussi