共用方式為


HttpClientHandler.DangerousAcceptAnyServerCertificateValidator 屬性

定義

取得一律傳回 true 的快取委派。

public:
 static property Func<System::Net::Http::HttpRequestMessage ^, System::Security::Cryptography::X509Certificates::X509Certificate2 ^, System::Security::Cryptography::X509Certificates::X509Chain ^, System::Net::Security::SslPolicyErrors, bool> ^ DangerousAcceptAnyServerCertificateValidator { Func<System::Net::Http::HttpRequestMessage ^, System::Security::Cryptography::X509Certificates::X509Certificate2 ^, System::Security::Cryptography::X509Certificates::X509Chain ^, System::Net::Security::SslPolicyErrors, bool> ^ get(); };
public static Func<System.Net.Http.HttpRequestMessage,System.Security.Cryptography.X509Certificates.X509Certificate2?,System.Security.Cryptography.X509Certificates.X509Chain?,System.Net.Security.SslPolicyErrors,bool> DangerousAcceptAnyServerCertificateValidator { get; }
[System.Runtime.Versioning.UnsupportedOSPlatform("browser")]
public static Func<System.Net.Http.HttpRequestMessage,System.Security.Cryptography.X509Certificates.X509Certificate2?,System.Security.Cryptography.X509Certificates.X509Chain?,System.Net.Security.SslPolicyErrors,bool> DangerousAcceptAnyServerCertificateValidator { get; }
public static Func<System.Net.Http.HttpRequestMessage,System.Security.Cryptography.X509Certificates.X509Certificate2,System.Security.Cryptography.X509Certificates.X509Chain,System.Net.Security.SslPolicyErrors,bool> DangerousAcceptAnyServerCertificateValidator { get; }
static member DangerousAcceptAnyServerCertificateValidator : Func<System.Net.Http.HttpRequestMessage, System.Security.Cryptography.X509Certificates.X509Certificate2, System.Security.Cryptography.X509Certificates.X509Chain, System.Net.Security.SslPolicyErrors, bool>
[<System.Runtime.Versioning.UnsupportedOSPlatform("browser")>]
static member DangerousAcceptAnyServerCertificateValidator : Func<System.Net.Http.HttpRequestMessage, System.Security.Cryptography.X509Certificates.X509Certificate2, System.Security.Cryptography.X509Certificates.X509Chain, System.Net.Security.SslPolicyErrors, bool>
Public Shared ReadOnly Property DangerousAcceptAnyServerCertificateValidator As Func(Of HttpRequestMessage, X509Certificate2, X509Chain, SslPolicyErrors, Boolean)

屬性值

一律傳回 true 的快取委派。

屬性

備註

特別是在測試案例中,常見的模式會使用 HttpClient 聯機到具有不應該驗證之憑證的伺服器,例如自我簽署憑證。 您通常會藉由將 ServerCertificateCustomValidationCallback 屬性設定為一律傳回True的委派來執行此HttpClientHandler動作;這表示憑證已通過驗證。 不過,並非所有實作都支援這個回呼,有些則擲回 PlatformNotSupportedException

屬性 DangerousAcceptAnyServerCertificateValidator 可解決這項限制。 屬性傳回的 DangerousAcceptAnyServerCertificateValidator 委派可以指派給 ServerCertificateCustomValidationCallback 屬性,如下列範例所示:

handler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;

這會提供 HttpClientHandler 實作已知的對象參考身分識別,以表達開發人員的意圖。 如果儲存在 屬性中的 ServerCertificateCustomValidationCallback 對象參考等於 DangerousAcceptAnyServerCertificateValidator,運行時間就能夠完全停用會擲回 PlatformNotSupportedException的平台上驗證。

開發人員可以利用這個屬性,更輕鬆地讓工具標記停用憑證驗證的危險,讓開發人員更輕鬆地傳送不安全的應用程式。

適用於