我有一个 asp.net 4.0 项目,它结合使用 Bouncy CaSTLe 和 .Net 框架来创建 X509 证书。
它在我的 W7 开发机器上运行正常,但是当安装在 W2008(32 位,不是 r2)上时,这段代码:
CX509CertificateRequestPkcs10 csr = new CX509CertificateRequestPkcs10();
抛出这个异常:
Unable to cast COM object of type 'System.__ComObject' to interface type 'CERTENROLLLib.CX509CertificateRequestPkcs10'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{728AB35B-217D-11DA-B2A4-000E7BBB2B09}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
最初我认为这可能是 64 位服务器的问题,因为 COM 仅兼容 32 位,但服务器是 32 位的。
该应用程序是使用 Framework 4.0 构建的,分配的 IIS AppPool 正在运行 4.0,集成模式,身份为“网络服务”- 与我的开发机器上使用的客户端浏览器 (IE8 32) 完全一样。
W2008-32(标准)是否没有开箱即用地实现 CERTENROLLLib?有谁知道如何让它在这种情况下表现出来?
感谢您的任何建议!
最佳答案
当您实例化 CX509CertificateRequestPkcs10 对象时,明确指定您要使用的接口(interface)(通过 ProgID)。在 Win2008 R2 中微软覆盖了接口(interface)。 而不是:
CX509CertificateRequestPkcs10 objPkcs10 = new CX509CertificateRequestPkcs10();
使用:
IX509CertificateRequestPkcs10 objPkcs10 = (IX509CertificateRequestPkcs10)Activator.CreateInstance(Type.GetTypeFromProgID("X509Enrollment.CX509CertificateRequestPkcs10"));
由于微软在 Win2008 R2 中覆盖了界面,如果代码是在 Win2008 R2 中编写的,运行时正在寻找新的界面 GUID,而在常规 Win2008 中找不到,因为 Win2008 R2 界面 GUID 与 Win2008 界面 Guid 不同.
因此,无法创建对象,结果抛出异常。
通过 ProgID 访问接口(interface)解决了问题。
参见:TechNet Answer - 在 W2008-32 上,创建 Pkcs10 对象时必须指定接口(interface) GUID,因为 R2 覆盖了旧的“标准”接口(interface)。
关于Asp.Net CertEnroll CX509CertificateRequestPkcs10异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11421502/