Member-only story
Fixing Let’s Encrypt Certificates renewal in .NET Core
Recently I faced some trouble with Let’s Encrypt Certificates renewal in a .NET Core web api published on a hosting with Plesk.
Usually Plesk should renew SSL certificates 30 days before their expiration.
In order to do so, Let’s Encrypt must be able to acces the url
https://www.example.com/.well-known/acme-challenge/[token file name]
Unfortunately I have a .NET Core app published in the root of my web hosting, thus every request gets passed to the .NET Core handler and the .well-know folder is not accessible as an http destination.
In this scenario Plesk could not auto-renew SSL certificates and I had to
- shutdown my .NET Core application
- renew SSL certificates by hand
- put the application back up and running
This is obviously not acceptable in a production environment.
I definitely had to fix this and here’s my solution.
I decided to try and make a new Controller, let’s call it LetsEncryptRenewController, in order to serve the correct file content to the Let’s Encrypt renewal tool when needed.
The code for the controller is as follows: