How to fix “Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster”
We were testing the deployment of a website onto 2 load balanced IIS 7 servers the other day, and the sites were loading fine. the next morning one of the testers was reporting an erorr on the website that said ”Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machinekey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster” . We looked at the error and realised that we need to create a static machinekey and add it into the web.config of both our IIS7 web servers to fix the issue.
Add following code in web.config.
<machinekey validationkey="AutoGenerate,IsolateApps" decryptionkey="AutoGenerate,IsolateApps" validation="SHA1" decryption="Auto" />