RemoteCertificateValidationCallback デリゲート
アセンブリ: System (system.dll 内)

Public Delegate Function RemoteCertificateValidationCallback ( _ sender As Object, _ certificate As X509Certificate, _ chain As X509Chain, _ sslPolicyErrors As SslPolicyErrors _ ) As Boolean
public delegate bool RemoteCertificateValidationCallback ( Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors )
public delegate bool RemoteCertificateValidationCallback ( Object^ sender, X509Certificate^ certificate, X509Chain^ chain, SslPolicyErrors sslPolicyErrors )
/** @delegate */ public delegate boolean RemoteCertificateValidationCallback ( Object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors )
戻り値
指定した証明書が認証に使用できるかどうかを判断する Boolean 値。

デリゲートの sslPolicyErrors 引数には、クライアントまたはサーバーの認証中に SSPI によって返されるすべての証明書エラーが格納されます。このデリゲートで呼び出されるメソッドによって返される Boolean 値は、認証が正常に許可されるかどうかを決定します。

RemoteCertificateValidationCallback クラスのインスタンスによって呼び出されるメソッドを実装するコード例を次に示します。検証エラーがある場合、このメソッドはそれらを表示し、認証されていないサーバーとの通信を防ぐ false を返します。
// The following method is invoked by the RemoteCertificateValidationDelegate. public static bool ValidateServerCertificate( object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { if (sslPolicyErrors == SslPolicyErrors.None) return true; Console.WriteLine("Certificate error: {0}", sslPolicyErrors); // Do not allow this client to communicate with unauthenticated servers. return false; }
前のコード例で定義されたメソッドを使用してデリゲートを作成するコード例を次に示します。
// Create a TCP/IP client socket. // machineName is the host running the server application. TcpClient client = new TcpClient(machineName,443); Console.WriteLine("Client connected."); // Create an SSL stream that will close the client's stream. SslStream sslStream = new SslStream( client.GetStream(), false, new RemoteCertificateValidationCallback (ValidateServerCertificate), null ); // The server name must match the name on the server certificate. try { sslStream.AuthenticateAsClient(serverName); } catch (AuthenticationException e) { Console.WriteLine("Exception: {0}", e.Message); if (e.InnerException != null) { Console.WriteLine("Inner exception: {0}", e.InnerException.Message); } Console.WriteLine ("Authentication failed - closing the connection."); client.Close(); return; }

Windows 98, Windows 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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- RemoteCertificateValidationCallback デリゲートのページへのリンク