When I use the new X509Certificate2(fileName, password, X509KeyStorageFlags.DefaultKeySet) to create certificate from certificate file containing private key in my web application, I got following error message:
In order to fix the issue, I have to change following IIS application pool setting:
1. Open IIS Mananger
2. Right click on the application pool the web site associated, select "Advanced Settings"
3. In the "Process Model" section, change "Load User Profile" value to true
4. Recycle application pool, the error will be gone.
System.Security.Cryptography.CryptographicException: The system cannot find the file specified.
at System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(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, X509KeyStorageFlags keyStorageFlags)
In order to fix the issue, I have to change following IIS application pool setting:
1. Open IIS Mananger
2. Right click on the application pool the web site associated, select "Advanced Settings"
3. In the "Process Model" section, change "Load User Profile" value to true
4. Recycle application pool, the error will be gone.
Comments