Client Certificate is always null on server side RRS feed

  • Question

  • I read a lot posts about how to send client certificate and did all of them but It is null on server side .

    I wrote this code on page mytest.aspx.cs
         protected void Page_Load(object sender, EventArgs e)
            string host = @"http://localhost:57855/Temp/index.aspx";
            string certName = @"C:\cert.pfx";
            string password = @"123456";


                X509Certificate2Collection certificates = new 

                certificates.Import(certName, password, 
                X509KeyStorageFlags.MachineKeySet | 

                ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) => true;

                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(host);
                req.AllowAutoRedirect = true;
                req.ClientCertificates = certificates;

                req.Method = "POST";
                req.ContentType = "application/x-www-form-urlencoded";
                string postData = "login-form-type=cert";
                byte[] postBytes = Encoding.UTF8.GetBytes(postData);
                req.ContentLength = postBytes.Length;

                Stream postStream = req.GetRequestStream();
                postStream.Write(postBytes, 0, postBytes.Length);
                WebResponse resp = req.GetResponse();

                Stream stream = resp.GetResponseStream();
                using (StreamReader reader = new StreamReader(stream))
                    string line = reader.ReadLine();
                    while (line != null)
                        line = reader.ReadLine();

            catch (Exception ex)

      and in index.aspx page I wrote this code

            protected void Page_Load(object sender, EventArgs e)
            bool b = false;
            if (HttpContext.Current.Request.ClientCertificate.IsPresent)
                b = true;//b is always  null


      also I'm using IIs express . in applicationhost file in C:\Users\Administrator\Documents\IISExpress\config  I change two part 


               <access sslFlags="SslNegotiateCert" />
                 <clientCertificateMappingAuthentication enabled="true" />

                 <iisClientCertificateMappingAuthentication  enabled="true">

    I installed cert.pfx in mmc=>Certificates/personal/certificates and 
    mmc=>certificates (current User)/personal/certificates

    but always in index page b is false.

    Also i shoud say cert.pfx is not a ssl certificate. It is a digital sign certificate and it has client authentication in cert's enhanskeyusage field

    Thursday, October 5, 2017 8:09 AM


  • I'd ask for help over here.






    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows Server] Datacenter Management

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.

    • Proposed as answer by Richard MuellerMVP Thursday, October 5, 2017 2:33 PM
    • Marked as answer by Just Karl Thursday, October 12, 2017 7:51 PM
    Thursday, October 5, 2017 12:39 PM