skip to Main Content

When a web project is created, Visual Studio automatically generates a SSL certificate and prompts you to install it. Everything works fine.

That certificate has now expired and I cannot figure out how to get it to re-generate one and start the process over again. I’ve tried deleting all existing localhost certificates from the certificate store and deleting secrets.json, but nothing seems to force it to re-start the generation process.

3

Answers


  1. Chosen as BEST ANSWER

    I finally figured it out.

    For anyone else who runs into this, the steps to fix it are:

    • All localhost certificates must be deleted in certificate manager. They can be found in Personal and Trusted Root
    • The secrets.json file must be deleted. This can be found in Users[user]AppDataRoamingMicrosoftUserSecrets
    • In powershell, re-run dotnet dev-certs https --trust to create and install a new one with the prompt to trust

    It will work after this again.


  2. From Visual Studio 2022 > Tools > Nuget Package Manager > Package Manager Console

    When the Package Manager Console display appears at the bottom, then type the command below

            PM > dotnet dev-certs https --clean
            //Cleaning HTTPS development certificates from the machine. A prompt might get displayed to confirm the removal of some of the certificates.
            //HTTPS development certificates successfully removed from the machine.
    
            PM > dotnet dev-certs https --trust
            //Trusting the HTTPS development certificate was requested.A confirmation prompt will be displayed if the certificate was not previously trusted.Click yes on the prompt to trust the certificate.
            //Successfully created and trusted a new HTTPS certificate.
    
            PM > dotnet dev-certs https --check
            //A valid certificate was found: C40087E6CA2F2A811F3BF78E3C5FE6BA8FA2XXXX - CN = localhost - Valid from 2023 - 01 - 27 23:21:10Z to 2024 - 01 - 27 23:21:10Z - IsHttpsDevelopmentCertificate: true - IsExportable: true
            //Run the command with both--check and --trust options to ensure that the certificate is not only valid but also trusted.
    

    Look at here for details

    Login or Signup to reply.
  3. I spent days trying to solve this and none of the above answers worked for me. The expired certificate didn’t exist anywhere when searching in the Microsoft Management Console. After running the dotnet dev-certs https --clean and --trust commands, the certificate used by my browsers was still expired.

    The solve for me was navigating to %APPDATA%ASP.NEThttps or C:Users{user}AppDataRoamingASP.NEThttps and removing the certificates there. They should have your project name i.e. myproject.key and myproject.pem. Delete those files, then rebuild and run your project. This should automatically generate new versions of the files and the browser should pick up the new certificate.

    Thanks to this post for providing the fix!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search