Condividi tramite


HttpClientHandler.DangerousAcceptAnyServerCertificateValidator Proprietà

Definizione

Ottiene un delegato memorizzato nella cache che restituisce truesempre .

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(); };
[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; }
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")>]
static member DangerousAcceptAnyServerCertificateValidator : Func<System.Net.Http.HttpRequestMessage, System.Security.Cryptography.X509Certificates.X509Certificate2, System.Security.Cryptography.X509Certificates.X509Chain, System.Net.Security.SslPolicyErrors, bool>
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)

Valore della proprietà

Delegato memorizzato nella cache che restituisce truesempre .

Attributi

Commenti

In particolare negli scenari di test, un modello comune usa HttpClient per connettersi a un server con un certificato che non deve essere convalidato, ad esempio un certificato autofirmato. Questa operazione viene eseguita in HttpClientHandler genere impostando la ServerCertificateCustomValidationCallback proprietà su un delegato che restituisce Truesempre . Questo indica che il certificato ha superato la convalida. Tuttavia, non tutte le implementazioni supportano questo callback e alcune generano PlatformNotSupportedException.

La DangerousAcceptAnyServerCertificateValidator proprietà risolve questa limitazione. Il delegato restituito dalla DangerousAcceptAnyServerCertificateValidator proprietà può essere assegnato alla ServerCertificateCustomValidationCallback proprietà , come nell'esempio seguente:

handler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;

In questo modo vengono fornite HttpClientHandler implementazioni di un'identità di riferimento a oggetti nota che esprime l'intenzione dello sviluppatore. Se l'oggetto archiviato nella ServerCertificateCustomValidationCallback proprietà è uguale a DangerousAcceptAnyServerCertificateValidator, il runtime è in grado di disabilitare completamente la convalida in una piattaforma che altrimenti genera un'eccezione PlatformNotSupportedException.

Come vantaggio collaterale, gli sviluppatori possono usare questa proprietà per rendere più semplice per gli strumenti di contrassegnare il pericolo di disabilitare la convalida dei certificati, che rende più semplice per gli sviluppatori evitare la spedizione di applicazioni non sicure.

Si applica a