SslStream.RemoteCertificate Proprietà

Definizione

Ottiene il certificato utilizzato per autenticare l'endpoint remoto.

public:
 virtual property System::Security::Cryptography::X509Certificates::X509Certificate ^ RemoteCertificate { System::Security::Cryptography::X509Certificates::X509Certificate ^ get(); };
public virtual System.Security.Cryptography.X509Certificates.X509Certificate? RemoteCertificate { get; }
public virtual System.Security.Cryptography.X509Certificates.X509Certificate RemoteCertificate { get; }
member this.RemoteCertificate : System.Security.Cryptography.X509Certificates.X509Certificate
Public Overridable ReadOnly Property RemoteCertificate As X509Certificate

Valore della proprietà

Oggetto X509Certificate che rappresenta il certificato fornito per l'autenticazione o null se non è stato fornito alcun certificato.

Eccezioni

L'autenticazione non è riuscita o non è stata effettuata.

Esempio

L'esempio di codice seguente illustra la visualizzazione del certificato restituito da questa proprietà.

   static void DisplayCertificateInformation( SslStream^ stream )
   {
      Console::WriteLine( L"Certificate revocation list checked: {0}", stream->CheckCertRevocationStatus );
      X509Certificate^ localCertificate = stream->LocalCertificate;
      if ( stream->LocalCertificate != nullptr )
      {
         Console::WriteLine( L"Local cert was issued to {0} and is valid from {1} until {2}.", 
             localCertificate->Subject, 
             localCertificate->GetEffectiveDateString(), 
             localCertificate->GetExpirationDateString() );
      }
      else
      {
         Console::WriteLine( L"Local certificate is null." );
      }

      X509Certificate^ remoteCertificate = stream->RemoteCertificate;
      if ( stream->RemoteCertificate != nullptr )
      {
         Console::WriteLine( L"Remote cert was issued to {0} and is valid from {1} until {2}.", 
            remoteCertificate->Subject, 
            remoteCertificate->GetEffectiveDateString(), 
            remoteCertificate->GetExpirationDateString() );
      }
      else
      {
         Console::WriteLine( L"Remote certificate is null." );
      }
   }


private:
static void DisplayCertificateInformation(SslStream stream)
{
    Console.WriteLine("Certificate revocation list checked: {0}", stream.CheckCertRevocationStatus);

    X509Certificate localCertificate = stream.LocalCertificate;
    if (stream.LocalCertificate != null)
    {
        Console.WriteLine("Local cert was issued to {0} and is valid from {1} until {2}.",
            localCertificate.Subject,
            localCertificate.GetEffectiveDateString(),
            localCertificate.GetExpirationDateString());
     } else
    {
        Console.WriteLine("Local certificate is null.");
    }
    // Display the properties of the client's certificate.
    X509Certificate remoteCertificate = stream.RemoteCertificate;
    if (stream.RemoteCertificate != null)
    {
    Console.WriteLine("Remote cert was issued to {0} and is valid from {1} until {2}.",
        remoteCertificate.Subject,
        remoteCertificate.GetEffectiveDateString(),
        remoteCertificate.GetExpirationDateString());
    } else
    {
        Console.WriteLine("Remote certificate is null.");
    }
}
Private Shared Sub DisplayCertificateInformation(stream As SslStream)
    Console.WriteLine("Certificate revocation list checked: {0}", stream.CheckCertRevocationStatus)
    Dim localCertificate As X509Certificate = stream.LocalCertificate

    If stream.LocalCertificate IsNot Nothing Then
        Console.WriteLine("Local cert was issued to {0} and is valid from {1} until {2}.", localCertificate.Subject, localCertificate.GetEffectiveDateString(), localCertificate.GetExpirationDateString())
    Else
        Console.WriteLine("Local certificate is null.")
    End If

    ' Display the properties of the client's certificate.
    Dim remoteCertificate As X509Certificate = stream.RemoteCertificate

    If stream.RemoteCertificate IsNot Nothing Then
        Console.WriteLine("Remote cert was issued to {0} and is valid from {1} until {2}.", remoteCertificate.Subject, remoteCertificate.GetEffectiveDateString(), remoteCertificate.GetExpirationDateString())
    Else
        Console.WriteLine("Remote certificate is null.")
    End If
End Sub

Commenti

Se la proprietà è accessibile, il certificato remoto non verrà eliminato quando l'istanza sslStream viene eliminata. Il chiamante della proprietà è responsabile della eliminazione dell'oggetto restituito X509Certificate .

Si applica a