Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component


Index of Chilkat Blog Posts

November 30, 2005

Add a Digital Certificate to ASP.NET’s Current User Certificate Store

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>


Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to support@chilkatsoft.com

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.