Single Sign On - don't make people login multiple times

If you need or want to split you website up into multiple seperate Asp.Net apps, it's nice not to make people login multiple times to access the different parts of it.

You just need to edit your web.config file specify a specific encryption key to use with the Asp authorisation cookies. Add a <machinekey> tag under <system.web>

If you can't be bothered editing each seperate web.config you can edit the machine wide config file under: %SystemRoot%\Microsoft.NET\Framework\--version--\CONFIG

<!-- We specify a particular key so that single sign works across all Apps -->
<machineKey validationKey="--128 hex chars--" decryptionKey="--48 hex chars" validation="SHA1"/>
		

Use the following program to generate new keys for use in validationKey & decryptionKey. Note, these are just random bit strings, not a Public Key pair. Use an input value of 128 for the validationKey and 48 for the decryptionKey

class KeyGen
{
	/// One or 2 args. First in number of hex characters to generator, Second is file to write to.
	static void Main(string[] argv)
	{
		int len = 128;

		if (argv.Length > 0)
			len = int.Parse(argv[0]);

		byte[] buff = new byte[len/2];

		RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();

		rng.GetBytes(buff);
		StringBuilder sb = new StringBuilder(len);

		for (int i=0; i 1 )
		{
			using( StreamWriter sw = File.CreateText( argv[1] ) )
				sw.WriteLine(sb);
		}
		else
		{
			Console.WriteLine(sb);
			Console.Read();
		}
	}
}
		

ssTk.co.uk
Last updated: 06 April 2012