title: ASP CrytographicException: Access is denied
body: <p>I’m trying to run a sample from an Azure SDK winch communicates with the Azure MFA service.  The sample compiles and runs in visual studio but once I deploy it to IIS I get the error below:</p>
  
  <blockquote>
    <p>Access is denied.</p>
  </blockquote>
  
  <p>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.</p>
  
  <pre><code>Exception Details: System.Security.Cryptography.CryptographicException: Access is denied.
  </code></pre>
  
  <p>I suspect it’s related to a certificate that is needed to authenticate to the Azure service but not sure how to troubleshoot as I’m not a developer by trade.   The certificate is in the same location as the ASP app and it’s referenced correctly in the code.  Again, the code works through Visual Studio.</p>
  
  <p>Stack Trace:</p>
  
  <pre><code>[CryptographicException: Access is denied.
  ]
     System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) +41
     System.Security.Cryptography.X509Certificates.X509Utils._QueryCertFileType(String fileName) +0
     System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromFile(String fileName, Object password, X509KeyStorageFlags keyStorageFlags) +125
     System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName, String password, X509KeyStorageFlags keyStorageFlags) +141
     pf_auth.send_message(String target, String message, String cert_file_path, String&amp; body) +221
     pf_auth.pf_authenticate_internal(PfAuthParams pfAuthParams, Boolean asynchronous, String&amp; otp, Int32&amp; call_status, Int32&amp; error_id) +744
     MFADemo.example.btnTest_Click(Object sender, EventArgs e) +1602
     System.Web.UI.WebControls.Button.OnClick(EventArgs e) +11754953
     System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +150
     System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3619
  </code></pre>