英語で読む

次の方法で共有


SslApplicationProtocol 構造体

定義

TLS アプリケーション プロトコルの値を表します。

public readonly struct SslApplicationProtocol : IEquatable<System.Net.Security.SslApplicationProtocol>
継承
SslApplicationProtocol
実装

次のコード例は、 でのアプリケーション レベルプロトコルのネゴシエーションを SslStream示しています。 サーバーは と protocol2のサポートをprotocol1アドバタイズします。 クライアントは、 と protocol3のサポートをprotocol2アドバタイズします。 一般的にサポートされるプロトコル (protocol2) は、ハンドシェイク中にネゴシエートされます。

async Task Server(NetworkStream stream, X509Certificate2 serverCertificate)
{
    using var server = new SslStream(stream);

    await server.AuthenticateAsServerAsync(new SslServerAuthenticationOptions
    {
        ServerCertificate = serverCertificate,
        ApplicationProtocols = new()
        {
            new("protocol1"),
            new("protocol2"),
        }
    });

    string protocol = Encoding.ASCII.GetString(server.NegotiatedApplicationProtocol.Protocol.Span);
    System.Console.WriteLine($"Server - negotiated protocol: {protocol}");
}

async Task Client(NetworkStream stream, string hostName)
{
    using var client = new SslStream(stream);

    await client.AuthenticateAsClientAsync(new SslClientAuthenticationOptions
    {
        // the host name must match the name on the certificate used on the server side
        TargetHost = hostName,
        ApplicationProtocols = new()
        {
            new("protocol2"),
            new("protocol3")
        }
    });

    string protocol = Encoding.ASCII.GetString(client.NegotiatedApplicationProtocol.Protocol.Span);
    System.Console.WriteLine($"Client - negotiated protocol: {protocol}");
}

// possible output:
//   Server - negotiated protocol: protocol2
//   Client - negotiated protocol: protocol2

注釈

この型には、HTTP バージョンの定義済みの SslApplicationProtocol 値を持つ静的フィールドが含まれています。

ハンドシェイク中に、クライアントは使用可能な ALPN プロトコルの一覧を送信し、サーバーはその一覧から最適な一致を選択します。

サポートされているプロトコルの完全な一覧については、「 TLS Application-Layer プロトコル ネゴシエーション (ALPN) プロトコル ID」を参照してください。

コンストラクター

SslApplicationProtocol(Byte[])

SslApplicationProtocolの新しいインスタンスを初期化します。

SslApplicationProtocol(String)

SslApplicationProtocolの新しいインスタンスを初期化します。

フィールド

Http11

HTTP/1.1 TLS アプリケーション プロトコルを表す SslApplicationProtocol を取得します。

Http2

HTTP/2 TLS アプリケーション プロトコルを表す SslApplicationProtocol を取得します。

Http3

SslApplicationProtocol HTTP 3.0 のインスタンスを定義します。

プロパティ

Protocol

この SslApplicationProtocol によって表される現行の TLS アプリケーション プロトコルを取得します。

メソッド

Equals(Object)

SslApplicationProtocol と指定したオブジェクトを比較します。

Equals(SslApplicationProtocol)

SslApplicationProtocol と指定した SslApplicationProtocol インスタンスを比較します。

GetHashCode()

SslApplicationProtocol インスタンスのハッシュ コードを返します。

ToString()

ToString() メソッドをオーバーライドします。

演算子

Equality(SslApplicationProtocol, SslApplicationProtocol)

2 つの SslApplicationProtocol オブジェクトを比較する等値演算子。

Inequality(SslApplicationProtocol, SslApplicationProtocol)

2 つの SslApplicationProtocol オブジェクトを比較する非等値演算子。

適用対象

製品 バージョン
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1