Last post Jul 20, 2015 04:01 AM by Li Wang
Jul 18, 2015 06:31 AM|tjackadams|LINK
Currently i am developing a Portal that will use a 3rd party API. The API itself is just a xml wrapped in a SOAP request that requires a Client Certificate to authenticate.
The issue i am having is that the site works perfectly fine from Visual Studio 2013 in debugging mode. However when i publish this to an IIS site (Using Publish to File System) the site no longer works.
I know it is a problem with the certificate and IIS not having access to it, but none of the fixes seemed to have worked. The environment is a Windows 2008 R2 server with IIS installed.
Here is a snippet of the code i believe is the issue
Dim objClientCertificate = New X509Certificate2(Hosting.HostingEnvironment.MapPath("~/Certificate.pfx"), "<Password>", X509KeyStorageFlags.MachineKeySet)
Dim myreq As HttpWebRequest = WebRequest.Create(url)
The Certificate.pfx has been installed to the local machine personal certificate store. The website is deployed to the DefaultAppPool (I have also tried creating its own AppPool) and the AppPool has been granted full access to the Private Key. This was done
by right-clicking the certificate -> All Tasks --> ~Manage Private Keys...
Here is the actual error i am receiving
Server Error in '/' Application.
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: Access denied.
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
[CryptographicException: Access denied.
System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) +41
System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromFile(String fileName, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx) +0
System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromFile(String fileName, Object password, X509KeyStorageFlags keyStorageFlags) +307
System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName, String password, X509KeyStorageFlags keyStorageFlags) +92
Portal.EthernetQuoteResult.Page_Load(Object sender, EventArgs e) +3925
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3178
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34249
Any suggestions on how to resolve this or debug this further would be very helpful. Just to Clarify the code works fine from Visual Studio, It's only when deployed to the IIS server that it becomes a problems.
Jul 20, 2015 04:01 AM|Li Wang|LINK
Welcome to ASP.NET forums.Please check your application pool. and see the value of Load User Profile property, and mark sure the value of it is True.
Right click your application pool->Advanced Settings->Process Model->Load User Profile