'Setting up SSL certificate in Visual Studio
I have a fresh install of Visual Studio Community 2019 on a new computer. I started a web app project, ran it for the first time, and then when prompted to accept the self-signed certificate I somehow managed to click "Do Not Ask Again" and "No".
At this point, when running the web app, I get a ERR_CONNECTION_RESET and can't connect to anything. I've tried deleting and recreating the certificate using advice listed here: Re-Installing Visual Studio 2017 Localhost Certificate, as well as reinstalling VS entirely, but neither worked.
To be clear, I messed up, not Visual Studio. As far as I can tell, there's nothing particular about my set up or environment, and I've built web apps in Visual Studio before, I just clicked the wrong things this time and am trying to undo that without factory resetting this entire PC.
Does anyone have any idea how I can trigger that original prompt in Visual Studio and get a properly signed certificate to run a web application?
[SOLVED]
Solution 1:[1]
If anyone has this very specific issue again, I'll post what I did to fix it (from this forum thread: https://developercommunity.visualstudio.com/t/cant-debug-aspnet-applications-err-connection-rese/1239592?viewtype=all)
1. In VS: Tools > Command Line > Developer Command Prompt, run
Edit: not needed, thanks lex-li!devenv /resetsettings
(this will also reset some customization settings)
- Remove potentially malformed certificates:
- In User Certificate Manager (certmgr.msc) AND Computer Certificate Manager (certlm.msc):
- Personal > Certificates > if a localhost certificate exists there, delete it
- Trusted Root Certification Authorities > Certificates > if a localhost certificate exists, delete it
- Repair IIS 10.0 Express:
- Control Panel > Programs & Features > Right Click IIS Express > Repair
- It will ask for a file path o a .msi installation file, but VS doesn't store one for IIS Express
- Look for a hidden file _package.json in the directory C:\ProgramData\Microsoft\VisualStudio\Packages\Microsoft.VisualStudio.IISExpress.Msi,version=xx.xx.xxxxx.xxx,chip=x64
- Copy the "url" (which should point to the correct .msi file) in _package.json into the file path asked for by the Repair prompt
- Verify the repair worked by running
netsh http show sslcert ipport=0.0.0.0:44390
in the command prompt (ensure the Certificate Hash field is present).
- Restart Visual Studio, debug your application, you should get the same Trusted Certificate prompt you misclicked the first time. (You can check the User Certificate Manager to see a new localhost certificate has been installed correctly)
Solution 2:[2]
You can create a self-signed certificate using dotnet dev-certs
It'll be stored in your PC's certificate store and VS will use it when scaffolding new projects with SSL support.
Solution 3:[3]
Simply open the terminal:
dotnet dev-certs https –-clean
and then
dotnet dev-certs https –-trust
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Ibrahim Abdelkareem |
Solution 3 | Jeremy Caney |