title: ASP.NET C# page with SSL and Mutual Auth from smartcard
body: <p>I would like create a login page for user with smartcard authentication and redirect to third party service. I have verified in java and it's work (but dont'know how).</p>
  
  <p>My Https Page have to read certificate with Request.ClientCertificate
  after i need to create a webrequest (a Soap Envelope) to 3th party services.
  When i execute this code on IIS Express locally , all works (private key of certificate is present)
  when i publish on remote IIS this code don't work , the message i receive is
  "Authorization Required" (private key of certificate is not present)</p>
  
  <p>This the code is use:</p>
  
  <pre><code>public HttpWebRequest CreateWebRequest(string url)
  {
  
  Uri uri = new Uri(url);
  HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
  System.Net.ServicePointManager.ServerCertificateValidationCallback += mIgnoreBadCertificates;
  webRequest.Proxy = null;
  webRequest.Headers.Add("SOAP:Action");
  webRequest.KeepAlive = true;
  webRequest.ProtocolVersion = HttpVersion.Version10;
  webRequest.Headers.Add("X-WASP-User", DataOnCertifcate);
  webRequest.ContentType = "text/xml;charset=\"utf-8\"";
  webRequest.Accept = "text/xml";
  webRequest.Method = "POST";
  webRequest.AuthenticationLevel = AuthenticationLevel.MutualAuthRequired;
  if (Request.ClientCertificate != null)
  {
       webRequest.ClientCertificates.Clear();
       webRequest.ClientCertificates.Add(Request.ClientCertificate);
  }
  return webRequest;
  
  }
  
  ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
  HttpWebRequest request = CreateWebRequest(Url);
  
  using (Stream stream = request.GetRequestStream())
  {
       envelope.Save(stream);
  }
  //ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
  IAsyncResult asyncResult = request.BeginGetResponse(null, null);
  asyncResult.AsyncWaitHandle.WaitOne();
  
  string soapResult = "";
  using (WebResponse webResponse = request.EndGetResponse(asyncResult))
  using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
  {
      soapResult = rd.ReadToEnd();
  }
  </code></pre>
  
  <p>1) on IIS there is SSL enabled
  2) When i access to my https page , browser show me a list of certificate.
  3) I choice the certificate present into smartcard, and i insert the Pin corretly
  4) my https test page , show me the correct certificate and public key information, but no private key information (on remote Server, meanwhile on local server all works)
  5) i Get this error</p>
  
  <p>401 Authorization Required  <h1>Authorization Required</h1> <p>This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.</p> <hr> Apache/2.2.3 (Red Hat) Server at server name Port 443  <br></p>
  
  <p>How can i fix this problem?</p>