【问题标题】:Visual Studio: "Failed trusting the certificate"Visual Studio:“信任证书失败”
【发布时间】:2022-01-16 18:31:03
【问题描述】:

在 Windows 10/11 上,使用 Visual Studio 2017-2022,当通过 HTTPS 使用 Kestrel 或 IIS 提供 Web API 时,Visual Studio 提示我信任 ASP.NET Core 生成的自签名证书。

如果我点击“是”,我会收到以下错误:

将证书添加到受信任的根证书存储失败 出现以下错误:信任证书失败。 (运行 Kestrel)或访问被拒绝。 (运行 IIS)

通过 Chrome 导航到 swagger UI 页面验证证书确实无效并且连接不安全。

运行dotnet dev-certs https --trust 导致

信任 HTTPS 开发者证书时出错。

从 certmgr 我可以看到 ASP.NET Core HTTPS 开发证书已安装在 Current User/Personal -store 中。我还看到了 Trusted Root Certification Authorities -store,以及里面的证书。

如果我尝试将证书拖放到 Trusted Root Certification Authorities -store,我会收到以下错误消息:

证书无法粘贴到受信任的根证书中 当局-商店。访问被拒绝。

如果我尝试将证书导入到上述商店,我会收到以下错误消息:

导入失败,因为存储是只读的,存储已满, 或者商店没有正确打开。

如果我尝试通过 'Install certificate' -> 'Current User' -> 'Place all certificates in the following store' -> Browse 从导出的文件安装证书,我根本看不到 Trusted Root Certification Authorities -store。

如果我选择'Certificates - Current User' -header, go to View -> Options, and enable 'Physical certificate stores',我可以将证书拖放到实体店Trusted Root Certification Authorities/Local Computer/Certificates

证书现在在 Trusted Root Certification Authorities 存储中可见,但 Visual Studio 仍然抛出相同的错误,浏览器认为证书不受信任,并且dotnet dev-certs https --check --trust 输出:

未找到有效证书。

如果我将原始证书留在个人中,不带私钥导出,并将导出导入实体店Trusted Root Certification Authorities/Local Computer/Certificatesdotnet dev-certs https --check --trust打印:

找到一个受信任的证书:...

...但是浏览器仍然认为证书无效,Visual Studio 抛出错误。

dotnet run 的结果相同,在 Visual Studio 中没有信任错误。 dotnet CLI 似乎没有检查或尝试信任证书。

相同但不同:如果我从 Chrome 保存证书并尝试通过 Chrome -> Settings -> Privacy and security -> Manage certificates -> Trusted Root Certification Authorities -> Import 将其添加到 受信任的根证书颁发机构,我还会收到:

导入失败,因为存储是只读的,存储已满, 或者商店没有正确打开。

我已经用完了要尝试的东西,这里可能缺少一些基本的东西。我该怎么办?

【问题讨论】:

    标签: .net windows visual-studio https ssl-certificate


    【解决方案1】:

    事实证明,虽然我确实删除了用户和机器存储中的所有 localhost 证书,并重新安装了 IIS,但在此过程中安装了某种错误的 localhost 证书,我需要再次删除它们,然后安装从浏览器到本地计算机证书受信任的根证书存储。

    希望这对将来的某人有所帮助。始终检查您的序列号。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-04
      • 1970-01-01
      • 2022-01-25
      • 2016-02-13
      • 1970-01-01
      • 1970-01-01
      • 2011-03-10
      相关资源
      最近更新 更多