HttpClientHandler.DangerousAcceptAnyServerCertificateValidator 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取始终返回 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的平台上完全禁用验证。
作为一个附带优势,开发人员可以使用此属性更轻松地让工具标记禁用证书验证的危险,从而使开发人员更容易避免交付不安全的应用程序。