SslStream.LocalCertificate 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得用於驗證本機端點的憑證。
public:
virtual property System::Security::Cryptography::X509Certificates::X509Certificate ^ LocalCertificate { System::Security::Cryptography::X509Certificates::X509Certificate ^ get(); };
public virtual System.Security.Cryptography.X509Certificates.X509Certificate? LocalCertificate { get; }
public virtual System.Security.Cryptography.X509Certificates.X509Certificate LocalCertificate { get; }
member this.LocalCertificate : System.Security.Cryptography.X509Certificates.X509Certificate
Public Overridable ReadOnly Property LocalCertificate As X509Certificate
屬性值
X509Certificate 物件,表示提供用於驗證的憑證或 null
(如果沒有提供憑證的話)。
例外狀況
驗證失敗或尚未執行驗證。
範例
下列程式代碼範例示範如何顯示此屬性傳回的憑證。
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