Troubleshoot untrusted localhost certificate in .NET Aspire

This article provides guidance on how to troubleshoot issues that you might encounter when working with untrusted localhost certificates in .NET Aspire.

Symptoms

Several .NET Aspire templates include ASP.NET Core projects that are configured to use HTTPS by default. If this is the first time you're running the project, and you're using Visual Studio, you're prompted to install a localhost certificate.

  • There are situations in which you trust/install the development certificate, but you don't close all your browser windows. In these cases, your browser might indicate that the certificate isn't trusted.

  • There are also situations where you don't trust the certificate at all. In these cases, your browser might indicate that the certificate isn't trusted.

Additionally, there are warning messages from Kestrel written to the console that indicate that the certificate is not trusted.

Possible solutions

  1. Close all browser windows and try again.

  2. If you're still experiencing the issue, then attempt to resolve this by trusting the self-signed development certificate with the .NET CLI. To trust the certificate, run the following commands. First, remove the existing certificates.

    Note

    This will remove all existing development certificates on the local machine.

    dotnet dev-certs https --clean
    

    To trust the certificate:

    dotnet dev-certs https --trust
    

    For more troubleshooting, see Troubleshoot certificate problems such as certificate not trusted.

See also