HttpListenerRequest.ClientCertificateError 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得錯誤碼,識別用戶端所提供之 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
備註
此屬性包含安全通道 (安全通道) 安全性支援提供者介面 (SSPI) 傳回的 Windows 錯誤碼,可用來驗證憑證。 如需 SSPI 支援安全通道的詳細資訊,請參閱 使用安全通道建立安全連線。