共用方式為


X509CertificateValidator.Validate(X509Certificate2) 方法

定義

在衍生類別 (Derived Class) 中覆寫時,驗證 X.509 憑證。

public:
 abstract void Validate(System::Security::Cryptography::X509Certificates::X509Certificate2 ^ certificate);
public abstract void Validate (System.Security.Cryptography.X509Certificates.X509Certificate2 certificate);
abstract member Validate : System.Security.Cryptography.X509Certificates.X509Certificate2 -> unit
Public MustOverride Sub Validate (certificate As X509Certificate2)

參數

certificate
X509Certificate2

X509Certificate2,表示要驗證的 X.509 憑證。

範例

public override void Validate(X509Certificate2 certificate)
{
    // Check that there is a certificate.
    if (certificate == null)
    {
        throw new ArgumentNullException("certificate");
    }

    // Check that the certificate issuer matches the configured issuer
    if (allowedIssuerName != certificate.IssuerName.Name)
    {
        throw new SecurityTokenValidationException
          ("Certificate was not issued by a trusted issuer");
    }
}
    Public Overrides Sub Validate(ByVal certificate As X509Certificate2)
        ' Check that there is a certificate.
        If certificate Is Nothing Then
            Throw New ArgumentNullException("certificate")
        End If

        ' Check that the certificate issuer matches the configured issuer
        If allowedIssuerName <> certificate.IssuerName.Name Then
            Throw New SecurityTokenValidationException("Certificate was not issued by a trusted issuer")
        End If

    End Sub
End Class

備註

覆寫 Validate 方法來指定驗證 X.509 憑證的方式。

如果傳遞至 certificate 參數中的 X.509 憑證未通過驗證,就會擲回 SecurityTokenValidationException

適用於