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:
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):
1 |
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:
As next Visual Studio should show you the certificate, where you click on Yes once more:
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.
Do i need to create it for every port i use to host or is there any way it will start creating again automatically.
Hi manish,
Yes, unfortunately. Or you can install IIS Express from scratch as I described in https://improveandrepeat.com/2021/01/a-simple-way-to-fix-ssl_error_rx_record_too_long-in-iis-express/
Regards,
Johnny
+1
Thank you so much for this! Saved me a ton of time.
Thank you so much. You made my day
Wonderful !
Thanks a lot !
nicely done and an excellent heads-up. thank you.
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
In this case you may need to reinstall IIS Express as described here: https://improveandrepeat.com/2021/01/a-simple-way-to-fix-ssl_error_rx_record_too_long-in-iis-express/
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).
Many thanks, been struggling with this all day.
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
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:
The 7148 will be different for your web site, the ASP.Net uses a random port number.
I hope this helps.
Regards,
Johnny
This saved me today! Thank you!
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.
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.