125

I am working on a fabric application where I have configured HTTPS. It is throwing an exception though I have a valid installed certificate.

Balanjaneyulu K
  • 2,556
  • 5
  • 21
  • 32

21 Answers21

228

These instructions from this blog worked for me

  1. dotnet dev-certs https --clean
  2. dotnet dev-certs https -t
  3. Restart VS
Peter Morris
  • 16,193
  • 8
  • 71
  • 124
63

I am on OSX and dotnet dev-certs https --clean and sudo dotnet dev-certs https --clean were not working for me. Finally I was able to fix it with the following steps.

  1. Go into Keychain Access
  2. Unlock System Keychain
  3. Delete the localhost certificate
  4. Run dotnet dev-certs https -t

You should now be able to run without the error.

Edit:

If, after following the above answer, you do run into an error that reads There was an error saving the HTTPS developer certificate... check out this answer https://stackoverflow.com/a/56709117/621827

Stephen Gilboy
  • 4,662
  • 1
  • 32
  • 32
57

Solution

(for Windows, not sure if there's an equivalent issue/solution for other OSs)

In a command prompt or Powershell terminal:

  • Run certmgr.msc and delete all localhost certificates under both Personal\Certificates and Trusted Root Certification Authorities\Certificates.
  • Then run dotnet dev-certs https -t a single time to create and trust a new development certificate.
  • Verify by running dotnet dev-certs https --check --verbose, or just try debugging your ASP.NET app again.

You may also need to run dotnet dev-certs https --clean before creating the new certificate.

hikarikuen
  • 690
  • 8
  • 14
  • 3
    Thanks for this. For my I needed to go and delete all of the "localhost" certs in certmgr.msc -> Personal\Certficates. I had tried all the other "things", and it didn't work until I did this. – atariman5000 Jan 28 '21 at 17:58
  • 2
    +1. There were a lot of junk localhost certificates under Personal\Certificates, even after running clean. Thank you. – hcd00045 Apr 06 '21 at 19:49
  • 1
    Cleaning the certificates under the certificate manager was also required in my case. May you please rewrite your answer to first provide the resolution steps? In its current form it is likely there are people who go away before reaching the actual solution. (I could edit your answer for doing so, but it may be too much of a change to be done by anyone but the author.) – Frédéric Jan 18 '22 at 09:25
21

For me the problem was resolved by running:

  1. dotnet dev-certs https --clean
  2. dotnet dev-certs https --verbose

enter image description here

Davor
  • 241
  • 2
  • 7
12

I had this issue on my Windows 10 system using visual studio. The problem seemed to be that the command used in the GUI to clear the local certs for HTTPS was failing with an error message that I can no longer reproduce.

The solution for me was to open the certmgr for the current windows account and to delete all of the personal localhost certs. There was ~20 certs there for me because I've tried re-creating them many times. After deleting all of those certs I ran my .Net core HTTPS API once more and everything worked!

In summary, open your certmgr for your current user and clear all personal/localhost certs.

  • 1
    this worked for me after the other answers didn't. Cleared two sets of localhosts under Personal and Trusted Root Certs. – WernerCD Dec 24 '20 at 17:56
8

For me deleting the files under file:\\%APPDATA%\Microsoft\SystemCertificates\My\Certificates and run in cmd dotnet dev-certs https -t solved my issue.

sta
  • 24,192
  • 8
  • 39
  • 53
Veleirian
  • 81
  • 1
  • 2
6

In windows, dotnet dev-certs https --clean doesn't work for me, I have to delete these localhost certs manually.

  1. Open certmgr.msc
  2. Delete all localhost certs under 'Trusted Root Certification Authorities/Certificates'
  3. Run dotnet dev-certs https -t
Liang
  • 747
  • 9
  • 13
4

Open RUN , then type mmc.exe, then

enter image description here

enter image description here

double click certificate

enter image description here

Delete localhost cert in both folders

enter image description here

then open your powershell

dotnet dev-certs https --clean
dotnet dev-certs https 
dotnet dev-certs https --trust
Suraj Rao
  • 28,850
  • 10
  • 94
  • 99
2

I had a similar (but not exactly the same) problem.
With 2.1 you have to configure your certificate.
I do this now completely in appsettings.json.
You can find my posting here:
Configure self hosting Kestrel App with certificate for https (internet web server)

Only have a look to the solution...

FredyWenger
  • 2,170
  • 2
  • 27
  • 33
1

If dotnet dev-certs https --clean not working.

  1. Open Run and open mmc.exe
  2. Inside MMC from File menu click on Add/Remove Snap-in.
  3. In the add/remove snap-in window, find certificates in available snap-ins and add it to the selected
  4. Pick User account
  5. In the console root -> Certificates Current User -> Personal click on Certificates
  6. You will see the list of issued and installed certificates for the current user. DON’T remove or change any certificates you don’t know, only remove certificates related to self-sign localhost ASP.NET Core.
Mehdi Daustany
  • 828
  • 3
  • 9
  • 21
1

If you are visiting this page and if you are unfortunate like me who tried every single solution/approach mentioned on this page but nothing worked, then you may like to know what I did and solved my problem.

I was getting this error from my ASP.NET Core web application no matter how many times I deleted the localhost certificates.

enter image description here

Then, I created a self-signed certificate using Powershell with this command. [I copied this PowerShell snippet from somewhere on the internet. Cannot remember the source.]

  $cert = New-SelfSignedCertificate -DnsName mydemowebapp.net -CertStoreLocation cert:\LocalMachine\My
  $pwd = ConvertTo-SecureString -String "MyPassword" -Force -AsPlainText
  Export-PfxCertificate -Cert $cert -FilePath C:\temp\cert.pfx -Password $pwd

Then, in my appsertings.Development.json, I added this entry.

  "Kestrel": {
    "EndPoints": {
      "Https": {
        "Url": "https://localhost:5000",
        "Certificate": {
          "Path": "C:\\temp\\cert.pfx",
          "Password": "MyPassword",
          "AllowInvalid": "true"
        }
      }
    }
  }

Ran the application, boom! problem solved. I used the same URL https://localhost:5000 as I found in my LaunceSettings.

enter image description here

I hate a solution like this, but at least I could continue my development with such a solution. I do not know what really happened recently that I had to face this issue. Was that a windows update? or something else? I don't know. I did not face this issue before, until recently. And yes, I remembered to run the Website in Kestrel rather than IIS.

Emran Hussain
  • 10,774
  • 5
  • 38
  • 46
0

I had the same issues and cleaning -> then installing certs helped me (another answer here). You also may issue a certificate as like for production server. Quite helpful to know.

cyberpug2077
  • 192
  • 1
  • 13
0

Not sure if this will help anybody else but I had exactly this issue on my Mac. I have the project in Dropbox and so it is shared across machines, on the '2nd' machine I had to go in and manually delete the 'obj' and 'bin' folders, then re-run the application and it all worked

Kevin Jones
  • 2,369
  • 16
  • 25
0

If you want to work with an environment that is not Development, don't forget that user secrets are only added automatically when env is Development.

You can use the AddUserSecrets methods to resolve this :

public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.ConfigureAppConfiguration((hostingContext, builder) =>
                {
                    var env = hostingContext.HostingEnvironment;
                    if (env.IsEnvironment("Local"))
                    {
                        builder.AddUserSecrets<Startup>();
                    }
                })
                .UseStartup<Startup>();
            });

see also : https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets?view=aspnetcore-3.1&tabs=windows#access-a-secret

0

I was having the same issue. The problem was that the project was with .net 4.6.1 and not .net core .

Fernando Moreira
  • 785
  • 4
  • 16
0

I run this on my command prompt. btw I am using Window 10 dotnet dev-certs https dotnet dev-certs https -t

0
  1. dotnet tool uninstall --global dotnet-dev-certs --version (required version)
  2. dotnet tool install --global dotnet-dev-certs
  3. dotnet dev-certs https --trust

For more details visit the GitHub issue page here also the official documentation Here

Jawahar05
  • 314
  • 8
  • 17
0

I ran into this problem and my solution was to restart. When I did and then reopened Visual Studio 2019, it asked me to accept a new SSL certificate. After that, I was able to run my program.

Dharman
  • 26,923
  • 21
  • 73
  • 125
dmrobotix
  • 65
  • 1
  • 9
0

One more detail - If you generally log in as a normal (non-admin) user, do NOT run the "dotnet dev-certs https" commands from an admin command prompt if you have a separate admin-level identity. Run them in a normal command prompt under your normal login. Ask me how I know. :-P

If you run these commands from an elevated command prompt (using a distinctly separate admin identity) you will experience the following:

  • "dotnet dev-certs https --trust" will work just fine
  • "dotnet dev-certs https --check --verbose" will tell you that everything is fine
  • VS Code will continue to spit out the "Unable to configure HTTPS endpoint ..." error when you try to start the debugger
  • You will continue to get "Certificate Not Trusted" warnings from your browser.

If you see these issues, run the "dotnet dev-certs https" commands from a normal command prompt. Fixed it for me. Hope this helps someone without spending the time that I did on this!

Steve G
  • 973
  • 1
  • 7
  • 14
0

Generate a new certificate:

$ dotnet dev-certs https --trust
The HTTPS developer certificate was generated successfully.
-2

I commented following line in 'Startup.cs' file, and it worked for me.

app.UseHttpsRedirection();
  • 1
    Comments are not fixes – JCKödel Apr 05 '21 at 21:33
  • commenting out this could help to get unblocked, in my project this was not the issue, manually had to update properties/launchSettings.json, remove from there the https url "applicationUrl": "http://localhost:5094", I know this is not the fix but while developing It is valid to use http only – Oswaldo Zapata May 07 '21 at 04:39