Getting and Checking your Machine Key in .NET

I QA’d some acceptance tests yesterday and got the old “doesn’t work on my machine”. Turns out there were some required environment settings, one of which was the machine key. Even though we have a wiki page with this info on, IMHO it’s good practise to get your tests to assert that environment conditions are met.

So here’s my quick test to ensure that the machine key is right. ( :

public void CheckMachineKey()
string devTeamValidationKey = "xxxx";
string devTeamDecryptionKey= "xxxx";

var machineKeySection = (MachineKeySection)ConfigurationManager.GetSection("system.web/machineKey");
Assert.That(machineKeySection.DecryptionKey, Is.EqualTo(devTeamDecryptionKey));
Assert.That(machineKeySection.Validation, Is.EqualTo(MachineKeyValidation.SHA1));

Many thanks to this post here: Encrypt Cookie using machine key

What did you think?

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s