This documentation is archived and is not being maintained.

LocalCertificateSelectionCallback Delegate

Selects the local Secure Sockets Layer (SSL) certificate used for authentication.

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

Public Delegate Function LocalCertificateSelectionCallback ( _
	sender As Object, _
	targetHost As String, _
	localCertificates As X509CertificateCollection, _
	remoteCertificate As X509Certificate, _
	acceptableIssuers As String() _
) As X509Certificate
Dim instance As New LocalCertificateSelectionCallback(AddressOf HandlerMethod)
/** @delegate */
public delegate X509Certificate LocalCertificateSelectionCallback (
	Object sender, 
	String targetHost, 
	X509CertificateCollection localCertificates, 
	X509Certificate remoteCertificate, 
	String[] acceptableIssuers
Not applicable.



An object that contains state information for this validation.


The host server specified by the client.


An X509CertificateCollection containing local certificates.


The certificate used to authenticate the remote party.


A String array of certificate issuers acceptable to the remote party.

Return Value

An X509Certificate used for establishing an SSL connection.

This delegate is used to construct instances of the SslStream class. The SslStream class is used to help secure information exchanged between a client and server. The client and server use this delegate to select a certificate to be used for authentication.

The following code example demonstrates a method implementation for this delegate.

public static X509Certificate SelectLocalCertificate(
    object sender,
    string targetHost, 
    X509CertificateCollection localCertificates, 
    X509Certificate remoteCertificate, 
    string[] acceptableIssuers)
    Console.WriteLine("Client is selecting a local certificate.");
    if (acceptableIssuers != null && 
        acceptableIssuers.Length > 0 &&
        localCertificates != null &&
        localCertificates.Count > 0)
        // Use the first certificate that is from an acceptable issuer.
        foreach (X509Certificate certificate in localCertificates)
            string issuer = certificate.Issuer;
            if (Array.IndexOf(acceptableIssuers, issuer) != -1)
                return certificate;
    if (localCertificates != null &&
        localCertificates.Count > 0)
        return localCertificates[0];
    return null;

The following code example demonstrates creating an instance of this delegate.

// Server name must match the host name and the name on the host's certificate. 
serverName = args[0];
// Create a TCP/IP client socket.
TcpClient client = new TcpClient(serverName,80);
Console.WriteLine("Client connected.");
// Create an SSL stream that will close the client's stream.
SslStream sslStream = new SslStream(
    new RemoteCertificateValidationCallback (ValidateServerCertificate), 
    new LocalCertificateSelectionCallback(SelectLocalCertificate)

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0