jeff_hinton
jeff_hinton

Reputation: 511

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?

Upvotes: 17

Views: 58011

Answers (5)

PHP Ferrari
PHP Ferrari

Reputation: 15616

Just follow these SS and re-run the project.

  1. Select Debug Properties under IIS Express (Google Chrome)
  2. Select Web and edit Project Url
  3. Click Create Virtual Directory button
  4. Also edit Overwrite application root url field

enter image description here

enter image description here

Upvotes: -1

Bazoo Studios LLC
Bazoo Studios LLC

Reputation: 359

Simply open the terminal:

dotnet dev-certs https --clean
dotnet dev-certs https --trust

Upvotes: 35

Jeff
Jeff

Reputation: 21

I had issue with SignalR client failing to connect/subscribe to localhost hub in development only, because the localhost dev cert was not a trusted root certificate; likely caused by browser security requirements.

Using 'MMC' export localhost 'ASP.NET Core HTTPS ...' cert from 'Personal Certificates' and import into 'Trusted Root Certificates'.

Upvotes: 2

jeff_hinton
jeff_hinton

Reputation: 511

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 devenv /resetsettings (this will also reset some customization settings) Edit: not needed, thanks lex-li!

  1. 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
  1. 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).
  1. 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)

Upvotes: 21

Ibrahim Abdelkareem
Ibrahim Abdelkareem

Reputation: 973

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.

https://learn.microsoft.com/en-us/dotnet/core/additional-tools/self-signed-certificates-guide#create-a-self-signed-certificate

Upvotes: 0

Related Questions