Force HttpWebRequest to send client certificate
<p>I have a p12 certificate, that I load it in this way:</p>

<pre><code>X509Certificate2 certificate = new X509Certificate2(certName, password,
        X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet |
        X509KeyStorageFlags.Exportable);
</code></pre>

<p>It is loaded correcty, in fact If i do <code>certificate.PrivateKey.ToXmlString(true);</code> it returns a complete xml without errors.
But If I do:</p>

<pre><code>try
{
    X509Chain chain = new X509Chain();
    var chainBuilt = chain.Build(certificate);
    Console.WriteLine("Chain building status: "+ chainBuilt);

    if (chainBuilt == false)
        foreach (X509ChainStatus chainStatus in chain.ChainStatus)
            Console.WriteLine("Chain error: "+ chainStatus.Status);
}
catch (Exception ex)
{
    Console.WriteLine(ex);
}
</code></pre>

<p>it writes:</p>

<pre><code>Chain building status: False
Chain error: RevocationStatusUnknown 
Chain error: OfflineRevocation 
</code></pre>

<p>so when I do:</p>

<pre><code>        ServicePointManager.CheckCertificateRevocationList = false;
    ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) =&gt; true;
    ServicePointManager.Expect100Continue = true;
    Console.WriteLine("connessione a:" + host);
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(host);
    req.PreAuthenticate = true;
    req.AllowAutoRedirect = true;
    req.ClientCertificates.Add(certificate);
    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);
    postStream.Flush();
    postStream.Close();

    WebResponse resp = req.GetResponse();
</code></pre>

<p>the server says that the certificate is not sent/valid.</p>

<p>My question is: </p>

<ul>
<li>how can I sent the certificate even with chain build false?</li>
<li>there is another class to post a certificate that does not check the certificate validation before send it?</li>
</ul>

<p>many thanks.
Antonino</p>