SslApplicationProtocol Struktúra
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
A TLS-alkalmazásprotokoll értékét jelöli.
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)
- Öröklődés
- Megvalósítás
Példák
Az alábbi példakód az alkalmazásszintű protokoll egyeztetését mutatja be.SslStream A kiszolgáló meghirdeti az és protocol2a protocol1 . Az ügyfél meghirdeti az és protocol3a protocol2 . A gyakran támogatott protokoll (protocol2) tárgyalása a kézfogás során történik.
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
Megjegyzések
Ez a típus a HTTP-verziókhoz előre definiált SslApplicationProtocol értékeket tartalmazó statikus mezőket tartalmaz.
A kézfogás során az ügyfél elküldi az elérhető ALPN-protokollok listáját, és a kiszolgáló kiválasztja a legjobb egyezést a listából.
A támogatott protokollok teljes listáját lásd: TLS Application-Layer Protocol Negotiation (ALPN) Protocol IDs.
Konstruktorok
| Name | Description |
|---|---|
| SslApplicationProtocol(Byte[]) |
Inicializálja a SslApplicationProtocol. |
| SslApplicationProtocol(String) |
Inicializálja a SslApplicationProtocol. |
Mezők
| Name | Description |
|---|---|
| Http11 |
Lekéri a SslApplicationProtocol HTTP/1.1 TLS alkalmazásprotokollt. |
| Http2 |
Lekéri a SslApplicationProtocol HTTP/2 TLS alkalmazásprotokollt. |
Tulajdonságok
| Name | Description |
|---|---|
| Protocol |
Lekéri az aktuális TLS-alkalmazásprotokollt, amelyet ez SslApplicationProtocola . |
Metódusok
| Name | Description |
|---|---|
| Equals(Object) |
Összehasonlítja a SslApplicationProtocol megadott objektumot. |
| Equals(SslApplicationProtocol) |
Összehasonlítja a megadott SslApplicationProtocol példánytSslApplicationProtocol. |
| GetHashCode() |
A példány kivonatkódját SslApplicationProtocol adja vissza. |
| ToString() |
Felülbírálja a metódust ToString() . |
Operátorok
| Name | Description |
|---|---|
| Equality(SslApplicationProtocol, SslApplicationProtocol) |
Két SslApplicationProtocol objektum összehasonlításának egyenlőségi operátora. |
| Inequality(SslApplicationProtocol, SslApplicationProtocol) |
A két SslApplicationProtocol objektum összehasonlítása egyenlőtlenségi operátora. |