c# - 在 Windows Server 2012 R2 上加载 asp-net 核心中的客户端证书失败
问题描述
我有一个 ASP.NET Core 2.2 应用程序,它加载客户端证书以在连接到外部 API 时使用。该代码在使用 Visual Studio 在本地运行时运行良好,但在我们的服务器上运行时失败。
我在日志中收到以下错误:
2019-03-12 13:29:12.810 +01:00 [ERR] 连接 ID“0HLL6SPAO039S”,请求 ID“0HLL6SPAO039S:00000001”:应用程序引发了未处理的异常。Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException:Internal.Cryptography.Pal.CertificatePal.FilterPFXStore(Byte[] rawData, SafePasswordHandle password, PfxCertStoreFlags pfxCertStoreFlags) 在 Internal.Cryptography.Pal.CertificatePal.FromBlobOrFile(Byte[] rawData) 的未知错误 (0xc0000225) , String fileName, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags) at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(String fileName, String password, X509KeyStorageFlags keyStorageFlags) at Geomatic.TinglysningApi.Startup.GetClientCertificate() in C:\dev\TinglysningApi \地理。
加载证书的代码如下所示
private X509Certificate GetClientCertificate()
{
return new X509Certificate2(path, password, X509KeyStorageFlags.EphemeralKeySet);
}
我也尝试过使用其他 X509KeyStorageFlags 以及它们的组合,但它们都以相同的方式失败。
在服务器上,我尝试将我的应用程序作为 IIS 托管应用程序运行,并尝试使用我自己的用户和具有管理员权限的 cmd 从 cmd 运行它。
解决方案
推荐阅读
- jquery - 预加载器脚本 - 在页面加载之前更改 SVG 填充颜色
- android - firebase 回收器适配器不加载图像但显示数据
- selenium - 使用 Mocha、Chai 和 webdriver.io 在浏览器中显示测试结果时出现问题
- php - 处理绑定变量 Oracle/PHP 中的错误
- node.js - 将多个用户添加到节点 JS env 文件
- python-3.x - python中的索引和范围
- asp.net-core - 如何公开我的 ASP.NET Core Web api 以在没有 http 的情况下使用?
- html - 嵌套弹性盒容器中的文本溢出
- java - Java Spring - 如何设置环境?
- firefox - Firefox 中的 FxFlexFill 无法正常工作