asp.net client cert issue

P

Param R.

Hi all, I have an aspx page that needs to call a remote website that is
protected by client cert authentication. I have installed the client cert
and set permissions for IIS_WPG as per
http://support.microsoft.com/default.aspx?scid=kb;en-us;817854. I then
exported the cert to a DER encoded file.

Now here is my code:-

Dim h as httpwebrequest
h = Ctype(WebRequest.Create(strurl), httpwebrequest)

Dim mycert as X509Certificate =
X509Certificate.CreateFromCertFile("c:\inetpub\wwwroot\mycert.cer")
h.clientcertificates.add(mycert)

h.contenttype = "text/xml"
h.method = "POST"
h.contentlength = len(strbody)

Dim s as stream = h.getrequeststream()
Dim sw as new streamwriter(s)
sw.write(strbody)
sw.close()

Dim hr as httpwebresponse = Ctype(h.getresponse(), httpwebresponse)
Dim s2 as stream = hr.getresponsestream()
Dim sr as new streamreader(s2)
returnstr = sr.readtoend()
sr.close()

Now here is the error I am getting back:-

The underlying connection was closed: Could not establish secure channel for
SSL/TLS.

Any Ideas? Please help. The same code works for a page that is not protected
by Client Certs.

thanks!
 
J

Joerg Jooss

Param said:
Hi all, I have an aspx page that needs to call a remote website that
is protected by client cert authentication. I have installed the
client cert and set permissions for IIS_WPG as per
http://support.microsoft.com/default.aspx?scid=kb;en-us;817854. I then
exported the cert to a DER encoded file.

Now here is my code:-

Dim h as httpwebrequest
h = Ctype(WebRequest.Create(strurl), httpwebrequest)

Dim mycert as X509Certificate =
X509Certificate.CreateFromCertFile("c:\inetpub\wwwroot\mycert.cer")
h.clientcertificates.add(mycert)

h.contenttype = "text/xml"
h.method = "POST"
h.contentlength = len(strbody)

Dim s as stream = h.getrequeststream()
Dim sw as new streamwriter(s)
sw.write(strbody)
sw.close()

Dim hr as httpwebresponse = Ctype(h.getresponse(), httpwebresponse)
Dim s2 as stream = hr.getresponsestream()
Dim sr as new streamreader(s2)
returnstr = sr.readtoend()
sr.close()

Now here is the error I am getting back:-

The underlying connection was closed: Could not establish secure
channel for SSL/TLS.

Any Ideas? Please help. The same code works for a page that is not
protected by Client Certs.

Either the server-side rejected your policy or your current
ICertificatePolicy rejected the server certificate. Verify that both certs
are OK.

Cheers,
 

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

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,237
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top