Ignoring SSL Certificate Errors On .NET Core On HttpClient

Written by William Roush on December 20, 2016 at 8:28 pm

Had a certificate expire at 8PM EST tonight on a critical project I was supposed to demo, wasn’t going to stop me… lots of articles don’t really go over how to do this now on .NET Core 1.0, so lets cover the code to do so:

using (var httpClientHandler = new HttpClientHandler())
   httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; };
   using (var client = new HttpClient(httpClientHandler))
       // Make request here.

Pretty simple, really.

This entry was posted in .NET and tagged , , on by .

About William Roush

William Roush is currently employed as a Senior Software Developer and independent contractor in Chattanooga, Tennessee. He has more than 12 years of experience in the IT field, with a wide range of exposure including software development, deploying and maintaining virtual infrastructure, storage administration and Windows administration.

4 thoughts on “Ignoring SSL Certificate Errors On .NET Core On HttpClient

  1. Peter Mills

    Thank you for writing this, I have been searching for how to do this all day for our development environment, as the old .Net way of doing it doesn’t work anymore.

  2. Christian Casutt

    i tried that and i get:

    Severity Code Description Project File Line Suppression State
    Error CS1061 ‘HttpClientHandler’ does not contain a definition for ‘ServerCertificateCustomValidationCallback’ and no accessible extension method ‘ServerCertificateCustomValidationCallback’ accepting a first argument of type ‘HttpClientHandler’ could be found (are you missing a using directive or an assembly reference?) InfrastructureManagerClientService C:\Users\blabla\Source\Repos\blabla\blabla\blabla.cs 79 Active

    did ‘they’ remove this definition?


Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.