İngilizce dilinde oku

Aracılığıyla paylaş


SslApplicationProtocol Yapı

Tanım

TLS Uygulama protokolünün değerini temsil eder.

C#
public readonly struct SslApplicationProtocol : IEquatable<System.Net.Security.SslApplicationProtocol>
Devralma
SslApplicationProtocol
Uygulamalar

Örnekler

Aşağıdaki kod örneği, üzerinde SslStreamuygulama düzeyi protokolü anlaşmasını gösterir. Sunucu ve protocol2için protocol1 desteği tanıtıyor. İstemci ve protocol3için protocol2 desteği tanıtıyor. Sık desteklenen protokol (protocol2) el sıkışması sırasında görüşülmektedir.

C#
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

Açıklamalar

Bu tür, HTTP sürümleri için önceden tanımlanmış SslApplicationProtocol değerler içeren statik alanlar içerir.

El sıkışması sırasında istemci kullanılabilir ALPN protokollerinin listesini gönderir ve sunucu bu listeden en iyi eşleşmeyi seçer.

Desteklenen protokollerin tam listesi için bkz. TLS Application-Layer Protokol Anlaşması (ALPN) Protokol Kimlikleri.

Oluşturucular

Alanlar

Http11

Temsil eden bir SslApplicationProtocol HTTP/1.1 TLS uygulama protokolü alır.

Http2

Temsil eden bir SslApplicationProtocol HTTP/2 TLS uygulama protokolü alır.

Http3

HTTP 3.0 için bir SslApplicationProtocol örnek tanımlar.

Özellikler

Protocol

Bu SslApplicationProtocoltarafından temsil edilen geçerli bir TLS uygulama protokolü alır.

Yöntemler

Equals(Object)

öğesini SslApplicationProtocol belirtilen nesneyle karşılaştırır.

Equals(SslApplicationProtocol)

bir SslApplicationProtocol değerini belirtilen SslApplicationProtocol örnekle karşılaştırır.

GetHashCode()

Örneğin karma kodunu SslApplicationProtocol döndürür.

ToString()

ToString() yöntemini geçersiz kılar.

İşleçler

Equality(SslApplicationProtocol, SslApplicationProtocol)

İki SslApplicationProtocol nesneyi karşılaştırmak için eşitlik işleci.

Inequality(SslApplicationProtocol, SslApplicationProtocol)

İki SslApplicationProtocol nesneyi karşılaştırmak için eşitsizlik işleci.

Şunlara uygulanır

Ürün Sürümler
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1