..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.
We did this, but when we refreshed the page, we were still getting the same error on the website. We tried hitting the sites in new browsers and they loaded fine. What we realised was that becuase we hadn’t shut down the browser, it was still using the old machine key, and as it didn’t match the autogenerated one on the webserver that the browser was hitting, we would get this error.
The steps to fix this are as follows:
1. Generate a new static machinekey and enter it into both web.config files.
2. Open a new browser window to test.

Here is a sample machinekey entry for your web.config file
<?xml version=”1.0″?>
<configuration>
    <appSettings/>
    <connectionStrings/>
    <system.web>

        <machineKey validationKey=’3AE041467624C0947FE562E2DBE6122B532FBC4AA9845AE3D82EC6AC473104EA40A27F8E89BADDAEE44B1F7582FC47299B674ED1FD2DDE1368710504EB2C54C1′ decryptionKey=’2FC79A393A5A463F82D38828F43ED7D030C418B448C9E76C’ validation=’SHA1′/>
    </system.web>
</configuration>

Comments