8

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:

enter image description here

After I clicked "Yes" then it generated error "Failed trusting the certificate" as shown in below screen shot:

enter image description here

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.

3
  • did you have valid self signed certs? run 'dotnet dev-certs https -c' plz Commented Dec 24, 2021 at 13:40
  • It is already mentioned in question. Commented Dec 28, 2021 at 4:06
  • I had this and cleaning certificate helped me: stackoverflow.com/a/70257639/1154773 Commented Dec 28, 2021 at 13:59

3 Answers 3

17

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": enter image description here

Step 2: Now locate and delete localhost certificate from the "Trusted Root Certification Authorities -> Certificate": enter image description here

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: enter image description here

Step 4: Start Visual Studio in Administrative mode and run your application. Click Yes if prompted to trust the self-signed certificate: enter image description here

Step 5: Now open "Manage user certificates" again and after selecting localhost click on Export: enter image description here

Step 6: Click on Next button: enter image description here

Step 7: Select "DER encoded binary X.509(.CER)" and click next: enter image description here

Step 8: Save the file to Desktop with the name "localhost.cer" enter image description here

Step 9: Now double click on the localhost.cer file that you just saved in Step 8 to install the certificate. enter image description here

Step 10: Install the certificate for the "Local Machine": enter image description here

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" enter image description here

Step 12: Repeat Steps 9 to 11 but this time install it for "Current User" and install it in "Trusted Publishers" certificate store. enter image description here

Step 13: Restart the Visual Studio and re-run your application and hope it will fix your problem.

Sign up to request clarification or add additional context in comments.

4 Comments

This didn't completely solve my problem. When I enter "dotnet dev-certs https --trust" I no longer get an error message, but when I start the server the certificate is still displayed as invalid in the browser. Do you know how to fix this error or what is causing it?
There are not enough upvotes to give for this, thank you!!!!
Confirmed that the 13 steps above plus the line dotnet dev-certs https --trust mentioned by DevNick above works a treat. Make sure to kill any worker processes etc too.
This solution is much more dangerous than OP bothered to notify readers of. Be warned if you delete your localhost cert you may render VS unable to connect to your local webserver at all which will not generate a new localhost cert. BACKUP your cert before absent mindedly deleting it.
2

Resolving this issue seems to be identical as to similar already posted question: Visual Studio 2017 gives 'Adding the Certificate to The Trusted Root Certificates store failed with the following Errror'

I would recommend to add the localhost certificate to Trusted Rood Certificates.

Comments

0

in cmd type dotnet --info if you can not see the correct version of net core installed then you need to install it again. in some cases you need to install dot net core 32 bit to resolve the problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.