Using pfx certificate to authenticate a webrequest

N

Nelson R.

Hi,

i need to get some info from a website page that requires an
certificate.

Ive got the provided certificate installed in IE, and when accessing
the website page, it shows a window to select the client certificate
and then shows the page correctly.

Im trying to do this by code (C# aspnet), using webrequest.

The certificate is in an pfx file and does not require password. I've
exported the file using IE to DER encoded binary X.509 (.cer).

My code:

X509Certificate certificate =
X509Certificate.CreateFromCertFile(Server.MapPath("file.cer"));
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create("https://websiteurl");
req.Method="POST";
req.ClientCertificates.Add(certificate);

HttpWebResponse result = (HttpWebResponse) req.GetResponse();
ReceiveStream = result.GetResponseStream();
// ...
// ...


I got this error:

System.Net.WebException: The underlying connection was closed: Could
not establish secure channel for SSL/TLS. --->
System.ComponentModel.Win32Exception: The message received was
unexpected or badly formatted at
System.Net.TlsStream.EndRead(IAsyncResult asyncResult) at
System.Net.Connection.ReadCallback(IAsyncResult asyncResult) --- End
of inner exception stack trace --- at
System.Net.HttpWebRequest.CheckFinalStatus() at
System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult) at
System.Net.HttpWebRequest.GetResponse()....


Can anyone help me about this subject?

Best regards,
Nelson R.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,709
Latest member
AustinMudi

Latest Threads

Top