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

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.

20 thoughts on “Recreate the Self-Signed HTTPS Certificate for Localhost in IIS Express”

  1. Do i need to create it for every port i use to host or is there any way it will start creating again automatically.

    Reply
  2. Thanks for the post.
    I was hopeful for this, but it didn’t resolve my problem. Still having the same issue of
    ERR_CONNECTION_REFUSED

    Reply
  3. Many thanks, Johnny – really useful.
    For the root cert, I copied the new IIS Express Development Certificate from Personal/Certificates to Trusted Root Certification Authorities/Certificates in Local Computer Certificate Manager. I think it’s the same result as doing the trusting via Visual Studio (not better, just an alternative).

    Reply
  4. Hi,
    didn’t understand where to run the command.
    “one of your applications (replace PORT with the port of your application)”
    what does it mean?
    thank you

    Reply
    • Hi bracha,
      You usualy run in the described problem if you run your application. If you see the error in the first screenshot of the post, check the URL in your web browser and copy it to a text file. The URL will be something like https://localhost:7148/… or https://127.0.0.1:7148/

      The port is the 4 digit number behind the :, in the example above 7148. You replace the PORT part of https://localhost:PORT/ with 7148 to get this command:

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

      The 7148 will be different for your web site, the ASP.Net uses a random port number.

      I hope this helps.

      Regards,
      Johnny

      Reply
  5. Thanks so much for this. The other articles and even Microsoft’s site all suggested the same thing which wasn’t sufficient or wasn’t working for me.

    I did have to reboot and do it a second time but it has worked since for all of my sites that are having problems.

    Reply
  6. Thank you! Firefox suddenly started giving me a SEC_ERROR_INADEQUATE_KEY_USAGE error out of the blue, and I spent the last 2 hours beating my head against the wall; nothing worked. This fixed it.

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.