HttpListenerRequest.ClientCertificateError Свойство

Определение

Возвращает код ошибки, который указывает на неполадку, связанную с сертификатом X509Certificate, предоставленным клиентом.

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

Значение свойства

Значение Int32, содержащее код ошибки Windows.

Исключения

Клиентский сертификат еще не был инициализирован с помощью вызова методов BeginGetClientCertificate(AsyncCallback, Object) или GetClientCertificate()

-или-

Операция не завершена.

Примеры

В следующем примере кода проверяется это свойство, чтобы определить, содержит ли запрос действительный сертификат клиента.

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

Комментарии

Это свойство содержит код ошибки Windows, возвращаемый интерфейсом SSPI безопасного канала (Schannel), который используется для проверки сертификата. Дополнительные сведения о поддержке SSPI для Schannel см. в статье Создание безопасного подключения с помощью Schannel.

Применяется к

См. также раздел