Skip to main content

Posts

Showing posts from October, 2021

C# Check Expiry Date of SSL Certifcate

  Check Certificate Expiry Date in .NET Core | Steve Fenton DateTime notAfter = DateTime . UtcNow ; var httpClientHandler = new HttpClientHandler { ServerCertificateCustomValidationCallback = ( request , cert , chain , policyErrors ) => { notAfter = cert . NotAfter ; return true ; } }; using HttpClient httpClient = new HttpClient ( httpClientHandler ); await httpClient . SendAsync ( new HttpRequestMessage ( HttpMethod . Head , url )); Assert . IsTrue ( notAfter > DateTime . UtcNow . AddDays ( 60 ));