I am consistenly receiving the following error when developing and authenticating locally in Visual Studio:
AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: NotValidTime, UntrustedRoot
Among others, it happens when using HttpClient
to call one of our backend-endpoints (localhost
) from one of our projects, so it all happens locally.
The certificate was signed/valid from this date last year, and has now run out after a year. None of the other developers on my team are receiving it or had the same problem.
I have then tried a lot of stuff, among others:
dotnet dev-certs https --clean
,dotnet dev-certs https
anddotnet dev-certs https --trust
, which sucessfully updated/re-created a certificate that expires in 2023 - still doesn't work/still receiving the same error though.- Updating certificate in Microsoft Management Console as per these links
We don't have a centralized authentication procedure - it is spread around the system in various places and scenarios, so I am not able to use workarounds like if #DEBUG... //then ignore certificates
. I need to generate a valid certificate correctly.
CodePudding user response:
Delete your offending localhost certificates:
Control Panel -> Internet Options - > Content tab.
- Click Certificates and remove the ones you no longer require.
- Click the Clear SSL State button.
Follow instructions here to recreate new certificate for each of your localhost sites, paying attention to the port number:
CodePudding user response:
Cleaning all private keys from the following folder did the trick (I only had one, that I just renamed, which did the trick):
C:\Users\{User}\AppData\Roaming\ASP.NET\Https
Credit to this SO-post answer for the solution.