ASP.NET MVC:“发生内部错误。”与X509Certificate2证书加载时字节 [英] ASP.NET MVC: “An internal error occurred.” when loading certificate bytes with X509Certificate2

查看:500
本文介绍了ASP.NET MVC:“发生内部错误。”与X509Certificate2证书加载时字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经花了几个小时来解决此问题。奇怪的是,当我使用这个独立的图书馆,它工作绝对没问题,但是当我与他们整合我的ASP .NET MVC的网站,它开始扔以下异常。我还使用了基于建议<一MachineKeySet标志href=\"http://stackoverflow.com/questions/1345262/an-internal-error-occurred-when-loading-pfx-file-with-x509certificate2\">here但仍没有运气。任何人都可以请帮我摆脱这种异常。谢谢你。


  

发生内部错误。


  
  

说明:未处理的异常
  的执行过程中发生
  当前Web请求。请检查
  堆栈跟踪有关的详细信息
  该错误以及它起源于
  在code。


  
  

异常详细信息:
  System.Security.Cryptography.CryptographicException:
  发生内部错误。


  
  

源错误:


  
  

194线:如果
  (string.IsNullOrEmpty(p12FilePassword))
   196线:证书=新X509Certificate2(p12FileBytes,,X509KeyStorageFlags.MachineKeySet);
  197线:其他



解决方案

我找到了解决办法的此处。看起来像一个已知的问题。我用 X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable 标志一起,问题就消失了。其它的解决方法是改变applicationpool的身份LOCALSERVICE

I have already spent a few hours to resolve this error. The weird thing is when I use this libraries independently, it works absolutely fine but when I integrate them with my ASP .NET MVC website, it start throwing the following exception. I have also used MachineKeySet flag based on suggestion here but still no luck. Could anyone please help me to get rid of this exception. Thanks.

An internal error occurred.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Security.Cryptography.CryptographicException: An internal error occurred.

Source Error:

Line 194: if (string.IsNullOrEmpty(p12FilePassword)) Line 196: certificate = new X509Certificate2(p12FileBytes, "", X509KeyStorageFlags.MachineKeySet); Line 197: else

解决方案

I found the solution here. Looks like a known issue. I used X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable flags together and problem disappeared. Other solution is to change the identity of applicationpool to LOCALSERVICE.

这篇关于ASP.NET MVC:“发生内部错误。”与X509Certificate2证书加载时字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆