I installed Visual Studio 2022 and created a Blazor web assembly project. When I started the application, Visual Studio 2022 prompted to trust the self signed certificate that ASP.NET Core has generated. Please refer below screen shot:
After I clicked "Yes" then it generated error "Failed trusting the certificate" as shown in below screen shot:
Please help me to fix the error. I have also tried following command but it did not fix my issue:
dotnet dev-certs https --trust
Note: Visual Studio 2019 is also installed on my machine i.e. currently I am having both VS2019 and VS2022 installed on my machine.
Finally I was able to fix the problem and I am mentioning the steps which fixed my problem. It can be beneficial for someone:
Step 1: Open "Manage user certificates" by searching in Windows search bar and delete localhost certificate from "Personal -> Certificate":
Step 2: Now locate and delete localhost certificate from the "Trusted Root Certification Authorities -> Certificate":
Step 3: Open "Manage computer certificates" and delete localhost from both "Personal" and "Trusted Root Certification Authorities". It would be better if you take backup of your certificate before deleting it:
Step 4: Start Visual Studio in Administrative mode and run your application. Click Yes if prompted to trust the self-signed certificate:
Step 5: Now open "Manage user certificates" again and after selecting localhost click on Export:
Step 7: Select "DER encoded binary X.509(.CER)" and click next:
Step 8: Save the file to Desktop with the name "localhost.cer"
Step 9: Now double click on the localhost.cer file that you just saved in Step 8 to install the certificate.
Step 10: Install the certificate for the "Local Machine":
Step 11: Select "Place all certificates in the following store" option and browse the certificate store by clicking on the browse button. Then select "Trusted Root Certification Authorities"
Step 12: Repeat Steps 9 to 11 but this time install it for "Current User" and install it in "Trusted Publishers" certificate store.
Step 13: Restart the Visual Studio and re-run your application and hope it will fix your problem.