9

I have move to using VSCode instead of VS2019 but noticed this error comes up when I run.. It still works.. I just need to keep clicking to ignore the error. Is there some easy fix for this ?

3
  • Wondering the same thing. Visual Studio installs a certificate for localhost. wondering if there's a way to do the same from VS Code. have you been able to figure it out? Commented Apr 19, 2020 at 22:44
  • surprised I couldn't find an easy answer since it must be happening to a lot of people.. I just switched back to VS2019 .. ended up really missing intellisense things for c# Commented Apr 21, 2020 at 14:57
  • I had the same issue and I fixed it using the command that I've shared in the answer. Commented Apr 20, 2021 at 10:19

2 Answers 2

10

Follow these steps:

  1. Open terminal
  2. Run dotnet dev-certs https --trust and confirm the dialog
  3. Close VSCode
  4. Close all browser instances

To find more information, take a look at:

You may find the following commands useful:

  • Clear developer certificate: dotnet dev-certs https --clean
  • Generate a developer certificate: dotnet dev-certs https
  • Trust developer certificate: dotnet dev-certs https --trust
Sign up to request clarification or add additional context in comments.

3 Comments

Command is dotnet dev-certs https --clean
@GJ Correct. Thanks for catching that! 🙌 (I don't remember if --clear was really supported that time or it was a typo 😅)
In some cases, you might need to restart the browser after clearing the dev certs and trusting.
4

Open the terminal/CLI and run the below command (select the preferred profile - http or https or "IIS Express") from the launchsettings.json file of your .NET project

dotnet run --launch-profile https

Sample launchSettings.json below

    {
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:62471",
      "sslPort": 44313
    }
  },
  "profiles": {
    "http": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "launchUrl": "swagger",
      "applicationUrl": "http://localhost:5281",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "https": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": false, 
      "launchUrl": "swagger",
      "applicationUrl": "https://localhost:7260;http://localhost:5281",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development" 
      }
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "swagger",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

2 Comments

Thank you, @AHAMED AAQIB. It seems that the default profile that was getting launched was http and it needed to launch the https profile. I also found out that the first profile listed in launchsettings.json appears to be the default profile that is launched according to an answer to the what-is-dotnet-run-default-profile-setting-from-launchprofile-json post: stackoverflow.com/a/70615515/1617161
@iCode Yes you are right default profile is http. Also when we run dotnet run command it automatically picks up the default (First) profile. It is best practice to run through https profile to avoid errors such as connect ECONNREFUSED

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.