'SEC_ERROR_INADEQUATE_KEY_USAGE on accessing webapp published using Visual Studio

I created a Blazor Server webapp and published it from Visual Studio using right click on the project - publish. I am publishing to a local folder, amongst others the output includes MyProject.exe Running that works fine:

info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production

However I can not access my webapp on https://localhost:5001. Firefox gives me the error code SEC_ERROR_INADEQUATE_KEY_USAGE. There is no option to ignore it. Accessing it using Chrome just gives me HTTP ERROR 500. In the console where I started MyProject.exe I can find this error:

fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
      An unhandled exception has occurred while executing the request.
      System.InvalidOperationException: Cannot find the fallback endpoint specified by route values: { page: /_Host, area:  }.
         at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.DynamicPageEndpointMatcherPolicy.ApplyAsync(HttpContext httpContext, CandidateSet candidates)
         at Microsoft.AspNetCore.Routing.Matching.DfaMatcher.SelectEndpointWithPoliciesAsync(HttpContext httpContext, IEndpointSelectorPolicy[] policies, CandidateSet candidateSet)
         at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.<Invoke>g__AwaitMatch|8_1(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task matchTask)
         at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[3]

Can anyone help me with this? And yes, it's a private application and shall run locally on localhost. When I run my webapp from Visual Studio, everything works fine.



Solution 1:[1]

You can skip this error by copying your development certificates from the Personal category into the Trusted Root Certificates.

Open the certificates window. See how to open it https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-view-certificates-with-the-mmc-snap-in

Then copy your development certificates as shown in the picture enter image description here

Solution 2:[2]

I got the SEC_ERROR_INADEQUATE_KEY_USAGE error too when trying to debug my .Net 6 app with Visual Studio and Firefox. It worked fine on other browsers, just not Firefox. I found the answer on Super User here. Your question mentions that you can debug without issues, but perhaps this solution will still work for you.

Visual Studio generates its own CA and installs it into the Windows Certificate store for web development. You can configure Firefox to import CAs from the Windows Certificate Store by enabling the ImportEnterpriseRoots setting in Firefox.

Do the following to enable use of the Windows Certificate Store by Firefox:

  1. Open Firefox
  2. Navigate to "about:config"
  3. Search for "ImportEnterpriseRoots"
  4. Add it, setting it to true
  5. Restart Firefox (if you have multiple instances open, you must close them all)

Solution 3:[3]

I had a similar problem with the Angular proxy with an aspnetcore back end. The solution for me was to delete the certificate and key used by the proxy located in:

%AppData%\Roaming\ASP.NET\https

The proxy then regenerates a new certificate and can carry on as normal.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alper Ebicoglu
Solution 2 deadlydog
Solution 3 Dezzamondo