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
and dotnet 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.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.
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.