SslApplicationProtocol 構造体
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
TLS アプリケーション プロトコルの値を表します。
public value class SslApplicationProtocol : IEquatable<System::Net::Security::SslApplicationProtocol>
public readonly struct SslApplicationProtocol : IEquatable<System.Net.Security.SslApplicationProtocol>
type SslApplicationProtocol = struct
Public Structure SslApplicationProtocol
Implements IEquatable(Of 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
Async Function Server(stream As NetworkStream, serverCertificate As X509Certificate2) As Task
Using serverStream As SslStream = new SslStream(stream)
Dim options as New SslServerAuthenticationOptions() With
{
.ServerCertificate = serverCertificate,
.ApplicationProtocols = New List(Of SslApplicationProtocol) From
{
New SslApplicationProtocol("protocol1"),
New SslApplicationProtocol("protocol2")
}
}
Await serverStream.AuthenticateAsServerAsync(options)
Dim protocol As String = Encoding.ASCII.GetString(
serverStream.NegotiatedApplicationProtocol.Protocol.Span)
System.Console.WriteLine($"Server - negotiated protocol: {protocol}")
End Using
End Function
Async Function Client(stream As NetworkStream, hostName As String ) As Task
Using clientStream As SslStream = new SslStream(stream)
Dim options as New SslClientAuthenticationOptions() With
{
.TargetHost = hostName,
.ApplicationProtocols = New List(Of SslApplicationProtocol) From
{
New SslApplicationProtocol("protocol2"),
New SslApplicationProtocol("protocol3")
}
}
Await clientStream.AuthenticateAsClientAsync(options)
Dim protocol As String = Encoding.ASCII.GetString(
clientStream.NegotiatedApplicationProtocol.Protocol.Span)
System.Console.WriteLine($"Client - negotiated protocol: {protocol}")
End Using
End Function
' possible output:
' Server - negotiated protocol: protocol2
' Client - negotiated protocol: protocol2
この型には、HTTP バージョンの定義済みの SslApplicationProtocol 値を持つ静的フィールドが含まれています。
ハンドシェイク中に、クライアントは使用可能な ALPN プロトコルの一覧を送信し、サーバーはその一覧から最適な一致を選択します。
サポートされているプロトコルの完全な一覧については、「 TLS Application-Layer プロトコル ネゴシエーション (ALPN) プロトコル ID」を参照してください。
Ssl |
SslApplicationProtocolの新しいインスタンスを初期化します。 |
Ssl |
SslApplicationProtocolの新しいインスタンスを初期化します。 |
Http11 |
HTTP/1.1 TLS アプリケーション プロトコルを表す SslApplicationProtocol を取得します。 |
Http2 |
HTTP/2 TLS アプリケーション プロトコルを表す SslApplicationProtocol を取得します。 |
Http3 |
SslApplicationProtocol HTTP 3.0 のインスタンスを定義します。 |
Protocol |
この SslApplicationProtocol によって表される現行の TLS アプリケーション プロトコルを取得します。 |
Equals(Object) |
SslApplicationProtocol と指定したオブジェクトを比較します。 |
Equals(Ssl |
SslApplicationProtocol と指定した SslApplicationProtocol インスタンスを比較します。 |
Get |
SslApplicationProtocol インスタンスのハッシュ コードを返します。 |
To |
ToString() メソッドをオーバーライドします。 |
Equality(Ssl |
2 つの SslApplicationProtocol オブジェクトを比較する等値演算子。 |
Inequality(Ssl |
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 |
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。