This is a sample C# application that shows how to add a certificate (without private key) to ASPNET’s certificate store. It uses the Chilkat .NET certificate classes (CreateCS, CertStore, Cert) all of which are free.
<font face=courier size=2>
Chilkat.CreateCS ccs = new Chilkat.CreateCS();
// Load a .cer file into a Chilkat.Cert object.
Chilkat.Cert myCert = new Chilkat.Cert();
bool b = myCert.LoadFromFile(Server.MapPath("myCert.cer"));
if (b)
{
// Open the cert store read/write.
ccs.ReadOnly = false;
// PS> The logged-on user is most likely "ASPNET". You can see this in
// the System.Environment.UserName property.
Chilkat.CertStore cs = ccs.OpenCurrentUserStore();
if (cs != null)
{
// Add the certificate to the store. That’s all there is to it!
b = cs.AddCertificate(myCert);
if (!b)
{
TextBox4.Text = TextBox4.Text + "Failed to add certificate to store\r\n";
}
else
{
TextBox4.Text = TextBox4.Text + "Added certificate!\r\n";
}
}
else
{
TextBox4.Text = TextBox4.Text + "Failed to open cert store read/write\r\n";
}
}
else
{
TextBox4.Text = TextBox4.Text + "Failed to load myCert.cer\r\n";
}
</font>