HttpListenerRequest.ClientCertificateError Vlastnost

Definice

Získá kód chyby, který identifikuje problém s X509Certificate poskytnutým klientem.

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

Hodnota vlastnosti

Hodnota Int32 , která obsahuje kód chyby systému Windows.

Výjimky

Klientský certifikát ještě nebyl inicializován voláním BeginGetClientCertificate(AsyncCallback, Object) metod nebo GetClientCertificate()

-Nebo-

Operace stále probíhá.

Příklady

Následující příklad kódu zkontroluje tuto vlastnost a určí, jestli požadavek obsahuje platný klientský certifikát.

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

Poznámky

Tato vlastnost obsahuje kód chyby Systému Windows vrácený rozhraním SCHANNEL (Secure Channel) SSPI (Security Support Provider Interface), který se používá k ověření certifikátu. Další informace o podpoře SSPI pro Schannel najdete v tématu Vytvoření zabezpečeného připojení pomocí Schannel.

Platí pro

Viz také