Share via


HttpListenerRequest.ClientCertificateError プロパティ

定義

クライアントから提供された X509Certificate の問題を識別するエラー コードを取得します。

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

プロパティ値

Windows エラー コードを格納している Int32 値。

例外

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

注釈

このプロパティには、セキュリティで保護されたチャネル (Schannel) セキュリティ サポート プロバイダー インターフェイス (SSPI) によって返される Windows エラー コードが含まれています。これは、証明書の検証に使用されます。 Schannel の SSPI サポートの詳細については、「Schannel を使用したセキュリティで保護された接続の作成」を参照してください。

適用対象

こちらもご覧ください