AuthenticationException:由于证书链中的错误,远程证书无效:UntrustedRoot、NotValidTime

mnc*_*mnc 11 c# ssl-certificate visual-studio asp.net-web-api

在 Visual Studio 中进行本地开发和身份验证时,我始终收到以下错误:

AuthenticationException:由于证书链中的错误,远程证书无效:NotValidTime、UntrustedRoot

其中,当使用从我们的项目之一HttpClient调用我们的后端端点之一( )时会发生这种情况,因此这一切都发生在本地。localhost

该证书从去年的这个日期开始签署/有效,一年后现已失效。我团队中的其他开发人员都没有收到它或遇到相同的问题。

然后我尝试了很多东西,其中包括:

我们没有集中的身份验证程序 - 它分布在系统的各个地方和场景中,因此我无法使用像if #DEBUG... //then ignore certificates. 我需要正确生成有效的证书。

mnc*_*mnc 9

清除以下文件夹中的所有私钥就可以解决问题(我只有一个,我刚刚重命名,它就解决了问题):

C:\Users\{User}\AppData\Roaming\ASP.NET\Https

解决方案归功于此 SO-post 答案。


Rik*_*tel 5

就我而言,我的域的 SSL 证书已过期。因此,请检查您的域名证书到期日期。解决方案是更新域证书。

Temporary solution:跳过 SSL 证书验证。

var handler = new HttpClientHandler();
handler.ClientCertificateOptions = ClientCertificateOption.Manual;
handler.ServerCertificateCustomValidationCallback = 
    (httpRequestMessage, cert, cetChain, policyErrors) =>
{
    return true;
};

var client = new HttpClient(handler);
Run Code Online (Sandbox Code Playgroud)

参考:/sf/answers/3263880091/