title: Rest API Client configuration in web.config C#
body: <p>I need to use Https mutual authentication in a rest API client  since we only get the URI we can not add client certificate as we do for WCF.
  So I have added keys in my web .config as below :</p>
  
  <pre><code>&lt;appSettings&gt;
      &lt;add key="URI" value="https://localhost:8080/RestfulAPI/RestfulService.svc/restfulData" /&gt;
      &lt;add key="CertificateValue" value="certficatename"/&gt;
      &lt;add key="CertificateLocation" value="LocalMachine"/&gt;
      &lt;add key="CertificateStoreName" value="My"/&gt;
      &lt;add key="CertificateFindType" value="FindBySubjectName"/&gt;
  &lt;/appSettings&gt;
  </code></pre>
  
  <p>and I am using it in my client code as below:</p>
  
  <pre><code>X509Store store = new X509Store(ConfigurationManager.AppSettings["CertificateStoreName"], ConfigurationManager.AppSettings["CertificateLocation"]);
              store.Open(OpenFlags.ReadOnly);
              X509CertificateCollection certificates = store.Certificates.Find(ConfigurationManager.AppSettings["CertificateFindType"], ConfigurationManager.AppSettings["CertificateValue"], true);
              X509Certificate certificate = certificates[0];
              HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest;
              request.ClientCertificates.Add(certificate);
  
  HttpWebResponse response = request.GetResponse() as HttpWebResponse
  </code></pre>
  
  <p>Is this the right way to implement mutual authentication in REST API client ?</p>
  
  <p>Or if not can someone please help me with the correct approach?</p>