2017-10-03 5 views
0

クライアント証明書を送信する方法について多くの投稿を読んで、すべてを行いましたが、サーバー側ではnullです。 クライアント証明書はサーバー側で常にヌルです

は、私がページ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"; 

    try 
    { 

     X509Certificate2Collection certificates = new 
     X509Certificate2Collection(); 

     certificates.Import(certName, password, 
     X509KeyStorageFlags.MachineKeySet | 
     X509KeyStorageFlags.PersistKeySet); 

     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); 
     postStream.Flush(); 
     postStream.Close(); 
     WebResponse resp = req.GetResponse(); 

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

     stream.Close(); 
    } 
    catch (Exception ex) 
    { 
     //Console.WriteLine(e); 
    } 
} 

にこのコードを書いたとindex.aspxページに私が

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

} 

も私が使用しているIISが表現し、このコードを書きました。 applicationhostファイルにはC:私は変更\ Users \ユーザードキュメント\管理者\ IISExpress \ CONFIG 2つの部分

<security> 

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

     <iisClientCertificateMappingAuthentication enabled="true"> 
     </iisClientCertificateMappingAuthentication> 
     ......... 
     </security> 

私は、MMC =>証明書/個人/証明書および MMC =>証明書でcert.pfx(現在のユーザーをインストール)/個人/証明書

ただし、常にインデックスページbはfalseです。

また、cert.pfxはSSL証明書ではありません。これは、デジタル署名証明書であり、それは私が、サーバーでクライアント証明書失効リストをインストールし、コード内でSSL証明書をロードしたいなぜそれが

+0

解決さ

+0

私はクライアント証明書で証明書を使用します。彼のhttp/httpsリクエスト(sslまたはデジタル署名証明書)で証明書を添付する必要があります。 –

答えて

0
CERTのenhanskeyusageフィールドにクライアント認証を持っていますか? httpsを使用しますか?
関連する問題