我们有一个代码可以创建一个新的X509Certificate2,它在开发环境中运行良好。 IIS主机中的相同代码崩溃到以下堆栈跟踪:
An unhandled exception was thrown by the application.
System.Security.Cryptography.CryptographicException: Cannot find the requested object.
at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
at System.Security.Cryptography.X509Certificates.X509Utils._QueryCertBlobType(Byte[] rawData)
at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData)
起初我以为我们为构造函数提供了空证书,但查看源代码告诉我,如果rawData为NULL或为空,应该会有一些不同的错误消息。
编辑1
我设法通过手动将证书安装到服务器,然后从存储中获取它而不是动态创建它来解决问题。仍然不知道创作失败的原因。