Recreate the Self-Signed HTTPS Certificate for Localhost in IIS Express

As explained in my earlier post, Visual Studio creates a self-signed certificate for your web application that allows you to access your site over HTTPS. If you accidentally remove this certificate, your web application will fail to load and report something like ERR_CONNECTION_RESET on the default error page of your browser:

Error Message in the browser is no big help

With caching and no way to show the current internal configuration of IIS Express, creating a new working self-signed certificate for localhost can be a challenge. If at the end of those steps your IIS Express still does not work, do it once more. It is a surprise how those things after the second or third round start working.

Start a Command Prompt (cmd) as Administrator, go to the folder "c:\Program Files (x86)\IIS Express" and run this command for one of your applications (replace PORT with the port of your application):

IisExpressAdminCmd.exe setupsslUrl -url:https://localhost:PORT/ -UseSelfSigned

If this command succeeded, restart Visual Studio and compile your application.

If you now start your application, you should get this dialog where you can click Yes:

Do you want to trust the self-signed certificate?

As next Visual Studio should show you the certificate, where you click on Yes once more:

The second dialog to trust the certificate

Your browser should now open your application without any problems and your other applications on localhost should work as well. Is this not the case, restart your computer and do the steps one more time.