Search code examples
c#visual-studioasp.net-web-apissl-certificate

AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot, NotValidTime


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:

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.


Solution

  • 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.