If it is a webfarm with dynamic load balancing, you may see this error. Basically what is happening is, a server is serving the request for a page and the page is posted back to a different server. The two servers use different keys to encrypt the viewstate information. The server that receives the postback request tries to decrypt the viewstate with its key which is different from the key it as encrypted. To fix this issue, you have to use the same key across all servers in your webfarm.
You can set this either in machine.config or your web.config. But it has to be the same across all servers.
<machinekey validationkey="<encryptionkey>" decryptionkey="<decryptionkey>" validation="SHA1" decryption="Auto" />
You can use this C# function to generate the keys:
public static string CreateMachineKey(int length)
{
byte[] random = new byte[length/2];
System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
rng.GetBytes(random);
System.Text.StringBuilder machineKey = new System.Text.StringBuilder(length);
for (int i = 0; i < random.Length; i++)
{
machineKey.Append(String.Format("{0:X2}", random[i]));
}
return machineKey.ToString();
}
The encryption key length can be between 40 and 128 and the decryption key lengh can be either 16 or 48. The recommended lengths are 128 for the encryption key and 48 for the decryption key.