Generate Machine Keys Using IIS

Views: This article has been read 43821 times.
Abstract: 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.

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:

  1. Open IIS 7.5.
  2. Select application’s virtual directory. (NOTE: Can be done on localhost and not where site is being hosted live.)
  3. Double-click on Machine Key icon in center pane.
  4. 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.
  5. Select Generate Keys link in right pane.
  6. 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.

By Todd Paholsky