Validation of viewstate MAC failed.

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.

This has been an annoying error of late for me. Mainly because I can’t replicate it. Here is some information I’ve found on it.

I’m dealing with this issue outside of the context of a webfarm, though in that context it could be that the keys have not been synchronized between servers.


This exception can appear if the following are true:

  1. You are not using a web farm
  2. You are using databound controls like GridView which use DataKeyNames
  3. You have a large page which loads slowly.

DataKeyNames forces the ViewState to be encrypted requiring a hidden field to be placed just before the end of the form tag. Apparently if you make a postback before the page finishes loading the that hidden field may not be a part of the form and therefore that form field value would not be returned. This can give you the exception (because the server doesn’t know that the ViewState is encrypted)

Possible Solutions

I’ve not tested any solutions here. I am just writing them for completeness and to find the information easily (I really dislike re-trawling through pages of information!)

Include this in the header of your page

<meta http-equiv="Page-Enter" content="RevealTrans(Duration=0,Transition=0)" />

This disables the page use until it is fully loaded. Thus ensuring the hidden field is created.

Also the following have come up:

  • Ensure you have no nested forms mistakenly in the page (like a master page)
  • <pages enableEventValidation="false" viewStateEncryptionMode="Never"/> Wouldn’t suggest it though unless you understand the security implications.
  • <pages enableEventValidation="false" viewStateEncryptionMode="Never" enableViewStateMac="false"/> – Wouldn’t suggest it though unless you understand the security implications.
  • An article (here) suggests that this error can occur when you are uing membership functionality.
  • One Person mentions this:

My issue was specific to IE7. Turned out to be a setting in Internet Options, Browsing History, Settings. Under Temporary Internet Files, radio button was on "Never". Changed it to "Everytime I visit the webpage". Cleared it right up.



Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: