SslApplicationProtocol Struct-datatyp

Definition

Representerar värdet för TLS Application Protocol.

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)
Arv
SslApplicationProtocol
Implementeringar

Exempel

I följande kodexempel visas förhandlingar om protokollet på programnivå på SslStream. Servern annonserar stöd för protocol1 och protocol2. Klienten annonserar stöd för protocol2 och protocol3. Det protokoll som vanligtvis stöds (protocol2) förhandlas under handskakningen.

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

Kommentarer

Den här typen innehåller statiska fält med fördefinierade SslApplicationProtocol värden för HTTP-versioner.

Under handskakningen skickar klienten en lista över tillgängliga ALPN-protokoll och servern väljer den bästa matchningen från listan.

En fullständig lista över protokoll som stöds finns i PROTOKOLL-ID:t för TLS Application-Layer Protocol Negotiation (ALPN).

Konstruktorer

Name Description
SslApplicationProtocol(Byte[])

Initierar en ny instans av SslApplicationProtocol.

SslApplicationProtocol(String)

Initierar en ny instans av SslApplicationProtocol.

Fält

Name Description
Http11

Hämtar ett representerande SslApplicationProtocol HTTP/1.1 TLS-programprotokoll.

Http2

Hämtar ett SslApplicationProtocol representerande HTTP/2 TLS-programprotokoll.

Egenskaper

Name Description
Protocol

Hämtar ett aktuellt TLS-programprotokoll som representeras av detta SslApplicationProtocol.

Metoder

Name Description
Equals(Object)

SslApplicationProtocol Jämför med det angivna objektet.

Equals(SslApplicationProtocol)

Jämför en SslApplicationProtocol med den angivna SslApplicationProtocol instansen.

GetHashCode()

Returnerar hash-koden för instansen SslApplicationProtocol .

ToString()

Åsidosätter ToString() metoden.

Operatorer

Name Description
Equality(SslApplicationProtocol, SslApplicationProtocol)

Likhetsoperatorn för att jämföra två SslApplicationProtocol objekt.

Inequality(SslApplicationProtocol, SslApplicationProtocol)

Ojämlikhetsoperatorn för att jämföra två SslApplicationProtocol objekt.

Gäller för