我面临以下问题.
我运行以下代码
var binaryData = File.ReadAllBytes(pathToPfxFile);
var cert = new X509Certificate2(binaryData, password);
分为两个过程.其中一个进程在LOCAL_SYSTEM
以下运行,代码成功.另一个在IIS中运行,使用属于"用户"本地组的本地用户帐户,在那里我得到以下异常:
System.Security.Cryptography.CryptographicException
Object was not found.
at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
at System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[] rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx)
at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password)
//my code here
所以我在谷歌上搜索了一下,找到了this answer个类似的问题.我try 为应用程序池启用LoadUserProfile
,现在它可以工作了.
问题是我不知道当我设定LoadUserProfile
的时候会发生什么,以及可能产生什么后果.我的意思是,如果这是一个"好"的东西,那么为什么它在默认情况下不"开",为什么它毕竟存在?
当我在IIS池中设置LoadUserProfile
时,会发生什么?它会产生什么负面后果?