Visual Studio: Create self-signed certificate for ClickOnce (.pfx)

When you want to create a ClickOnce deployment you should sign the automatically generated manifest using an Authenticode certificate, providing a certificate took from the local computer cert store or passing a .pfx file.

To create an homemade self-signed .pfx file (for testing purpose only!!!), open the “Visual Studio Command Promt (2010)” or the “Developer Command Prompt for VS2012” and run the following two steps:

 

makecert.exe -sv TestCodeSign.pvk -n “CN=Test Code Sign” TestCodeSign.cer

 

pvk2pfx.exe -pvk TestCodeSign.pvk -spc TestCodeSign.cer -pfx TestCodeSign.pfx -po password

 

If you want, you can also omit the password.

Now that you have your own homemade certificate you can use it, especially useful while using command-line tools like mage (or mageUI with GUI support).

Stay Tuned! 😉

Advertisements

C#: Enable Automatic Decompression on System.Net.WebClient

The WebClient class is really easy to use, but actually doesn’t provide so much control over the underline request, or so it seems, but we can still inherits from it to get the control over the WebRequest that the WebClient using.

With this in mind I’ve could extend the WebClient enabling the powerfull AutomaticDecompression of the HttpWebRequest, and getting compressed web resources:

public class AutomaticDecompressionWebClient : WebClient
{
	protected override WebRequest GetWebRequest(Uri address)
	{
		var request = base.GetWebRequest(address) as HttpWebRequest;
		if (request == null) throw new InvalidOperationException("You cannot use this WebClient implementation with an address that is not an http uri.");
		request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
		return request;
	}
}