C# code to use client certificates

261 views Asked by At

Success so far:

I am developing an Asp.net application to subscribe to a web-service from a third party site. ( It is working fine with http, to pass data and receive results).

Brick wall:

The next step is to use client certificate. The server would then be https. I am given a client certificate, and I am supposed to use the client certificate (a .crt file) to make the communication secure. How do I use this in my C# asp.net application?

I am new to this, and need help. Thanks. Brett.

1

There are 1 answers

0
XsiSecOfficial On

Here you go :)

string username;
username = User.Identity.Name;
message.Text = "Welcome " + username;
HttpClientCertificate cert = Request.ClientCertificate;
if (cert.IsPresent)
{
  certData.Text = "Client certificate retrieved";
}
else
{
  certData.Text = "No client certificate";
}

here is another way

  
string userName;
userName = User.Identity.Name;
greetingLabel.Text = "Welcome " + userName;
HttpClientCertificate cert = Request.ClientCertificate;
if (cert.IsPresent)
    certDataLabel.Text = cert.Get("SUBJECT O");
else
    certDataLabel.Text="No certificate was found.";