title: how to obtain SSL certificate information of a remote server in c#
body: <p>i have to develop an application in c# to obtain SSL certificate information like expiry date, issued by, etc based on the DNS (say *.google.com) I provide so that if expiry date is near I can proactively handle it.  If i provide the DNS as *.google.com then i need to obtain the details of SSL ceritificate information of that domain.</p>
  
  <p>I tried following <a href="http://awesomeideas.net/page/Cert-Expiry-Check.aspx" rel="noreferrer">http://awesomeideas.net/page/Cert-Expiry-Check.aspx</a>, but i feel it is for certificates stored in local system. i also tried using HttpWebRequest to obtain the details of SSL certificate, but it required me to enter a valid URI which in my case is not availble. i just have DNS name</p>
  
  <p>below is the code i used to obtain information using HttpWebRequest. but it required me to enter valid URI of type https://*.domain.com </p>
  
  <pre><code>Uri uri = new Uri(DNSEntry); 
  HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); 
  request.Method = WebRequestMethods.Http.Get; 
  HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 
  X509Certificate cert1 = request.ServicePoint.Certificate; 
  X509Certificate2 cert = new X509Certificate2(cert1); 
  DateTime dtCertExpiry = Convert.ToDateTime(cert.NotAfter.ToString());
  </code></pre>