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

注解

此属性包含安全通道 (SSPI) 安全支持提供程序接口 (SSPI) 返回的 Windows 错误代码,用于验证证书。 有关 SSPI 对 Schannel 的支持的详细信息,请参阅 使用 Schannel 创建安全连接

适用于

另请参阅