Export (0) Print
Expand All

HttpListenerRequest.ClientCertificateError Property

Note: This property is new in the .NET Framework version 2.0.

Gets an error code that identifies a problem with the X509Certificate provided by the client.

Namespace: System.Net
Assembly: System (in system.dll)

'Declaration
Public ReadOnly Property ClientCertificateError As Integer
'Usage
Dim instance As HttpListenerRequest
Dim value As Integer

value = instance.ClientCertificateError

/** @property */
public int get_ClientCertificateError ()

public function get ClientCertificateError () : int

Property Value

An Int32 value that contains a Windows error code.

This property contains a Windows error code returned by the Secure Channel (Schannel) Security Support Provider Interface (SSPI), which is used to validate the certificate. For more information about SSPI support for Schannel, see “Creating a Secure Connection Using Schannel” in the Security documentation at http://msdn.microsoft.com/library.

The following code example checks this property to determine whether the request includes a valid client certificate.

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;
}

Windows 98, Windows Server 2003, Windows XP Media Center Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft