Skip to main content

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));

Comments

Popular posts from this blog