title: using certificate in AZURE asp.net websites
body: <p>I am moving one asp.net app to azure environement.In the application we are using one X509Certificate2 while calling some webservices.I used cert.import method to import the certificate and then adding certificate object to client certificate property of service.It was working fine when we hosted our app on IIS servers.
  This is how we are doing it :</p>
  
  <pre><code>abcservice service = new abcservice ();
  </code></pre>
  
  <p><code>string CertificatePath = ConfigurationManager.AppSettings["CertificatePath"].ToString();
  string certPwd = ConfigurationManager.AppSettings["CertificatePwd"].ToString();</code></p>
  
  <pre><code>cert.Import(CertificatePath, certPwd , X509KeyStorageFlags.DefaultKeySet);
  service.ClientCertificates.Add(cert);
  </code></pre>
  
  <p>But when we move to azure ,it stops working and start showing me cant find specified file at cert.import .I came to know that MyStore is not working in Azure.So i am looking for some alternatives for that.I found one solution that how i can do this without using Import.</p>
  
  <pre><code>abcservice service = new abcservice ();
  
  string CertificatePath =ConfigurationManager.AppSettings["CertificatePath"].ToString();
  </code></pre>
  
  <p><code>string certPwd = ConfigurationManager.AppSettings["CertificatePwd"].ToString();</code></p>
  
  <pre><code>X509Certificate2 cert = new X509Certificate2(CertificatePath , certPwd , X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
  service.ClientCertificates.Add(cert);
  </code></pre>
  
  <p>Now it start adding certificate in service object but when i am calling service it start give me following Error : </p>
  
  <p><strong>Cannot find the X.509 certificate using the following search criteria: StoreName 'My', StoreLocation 'LocalMachine', FindType 'FindBySubjectName', FindValue 'abc-123.pqr.com'.</strong></p>
  
  <p>In web.config ,we have set following properties :</p>
  
  <pre><code>&lt;clientCertificate findValue="abc-123.pqr.com" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" /&gt;
          &lt;!--Need to provide Server certificate Details--&gt;
          &lt;serviceCertificate&gt;
            &lt;defaultCertificate findValue="xyz Gateway" storeLocation="LocalMachine" storeName="TrustedPeople" x509FindType="FindBySubjectName" /&gt;
            &lt;authentication certificateValidationMode="ChainTrust" revocationMode="Online" /&gt;
  </code></pre>
  
  <p>I have set up abc-123.pqr.com as DNS name for my website and i am able to access website using this URL and uploaded the certificate in azure portal against this URL.</p>