Friday, October 7, 2011

Validation of viewstate mac failed

At times when we host our web application to server, we get following error.

“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"

The root cause of this error is, variation in the key to encrypt and decrypt viewstate data. View state data is transferred between the client and the server is always validated. This is required to ensure that viewstate data is not tempered. Viewstate data is in envrypted formate and is decrypted while validating it, unique key is used to encrypt and decrypt viewstate data. When application is hosted on single machine, there is no issue of key, as key remains same for single machine. But in case of web farm or other hosting environment in that case we have to fix this issue by providing encryption key.

Add following line of in web.config under system.web tag
  
< / machinekey>


Machine key configuration



Even we can choose not to do validation of view state by adding following line of code, this disables validation of data which is not prefered in most of the environments.
Refer this link ---> http://msdn.microsoft.com/en-us/library/w8h3skw9.aspx
Submit this story to DotNetKicks

0 comments: