SslApplicationProtocol Struktur

Definition

Stellt einen Wert des TLS-Anwendungsprotokolls dar.

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)
Vererbung
SslApplicationProtocol
Implementiert

Beispiele

Im folgenden Codebeispiel wird die Aushandlung des Protokolls auf Anwendungsebene für SslStreamveranschaulicht. Der Server kündigt Unterstützung für protocol1 und an protocol2. Der Client kündigt Unterstützung für protocol2 und an protocol3. Das häufig unterstützte Protokoll (protocol2) wird während des Handshakes ausgehandelt.

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

Hinweise

Dieser Typ enthält statische Felder mit vordefinierten SslApplicationProtocol Werten für HTTP-Versionen.

Während des Handshakes sendet der Client eine Liste der verfügbaren ALPN-Protokolle, und der Server wählt die beste Übereinstimmung aus dieser Liste aus.

Eine vollständige Liste der unterstützten Protokolle finden Sie unter ALPN-Protokoll-IDs (TLS Application-Layer Protocol Negotiation).

Konstruktoren

SslApplicationProtocol(Byte[])

Initialisiert eine neue Instanz des SslApplicationProtocol.

SslApplicationProtocol(String)

Initialisiert eine neue Instanz des SslApplicationProtocol.

Felder

Http11

Ruft einen SslApplicationProtocol-Wert ab, der für das HTTP-/1.1-TLS-Anwendungsprotokoll steht.

Http2

Ruft einen SslApplicationProtocol-Wert ab, der für das HTTP-/2-TLS-Anwendungsprotokoll steht.

Http3

Definiert eine SslApplicationProtocol Instanz für HTTP 3.0.

Eigenschaften

Protocol

Ruft ein aktuelles TLS-Anwendungsprotokoll ab, das von SslApplicationProtocol dargestellt wird.

Methoden

Equals(Object)

Vergleicht die SslApplicationProtocol mit dem angegebenen Objekt.

Equals(SslApplicationProtocol)

Vergleicht ein SslApplicationProtocol mit der angegebenen SslApplicationProtocol-Instanz.

GetHashCode()

Gibt den Hashcode für die SslApplicationProtocol-Instanz zurück.

ToString()

Setzt die ToString()-Methode außer Kraft.

Operatoren

Equality(SslApplicationProtocol, SslApplicationProtocol)

Der Gleichheitsoperator zum Vergleichen zweier SslApplicationProtocol-Objekte.

Inequality(SslApplicationProtocol, SslApplicationProtocol)

Der Ungleichheitsoperator (=) zum Vergleichen von zwei SslApplicationProtocol-Objekten.

Gilt für: