When deploying an ASP.NET Web Application on a server that is part of a server farm, “Validation of viewstate MAC failed” errors can occur. To prevent this, IIS 7.5 provides a generate Machine Key feature to handle properly the view state application service.
Perform the following steps:
- Open IIS 7.5.
- Select application’s virtual directory. (NOTE: Can be done on localhost and not where site is being hosted live.)
- Double-click on Machine Key icon in center pane.
- Select “SHA1” from Encryption method drop down and “AES” from Decryption method drop down. Uncheck “Automatically generate at runtime” and “Generate a unique key for each application” checkboxes for both encryption and decryption keys.
- Select Generate Keys link in right pane.
- Add newly generated keys to the following markup in between the application’s web.config file's opening and closing system.web tags
machineKey validation=HA1 validationKey=[key] decryption=AES decryptionKey=[key]
WARNING: For security reasons, it’s best not to use online services to generate Machine Keys.