Jaa


ASP.NET Viewstate error - Validation of viewstate MAC failed

Last week I was working with on a case where they were getting this error message

HttpException (0x80004005): 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

Typically this occurrs if the application is on a webfarm and autogenerate is used as the validation key.  This is because if you request a page and click a button for example, the postback may go to another server in the web farm and if the validation keys don't match, asp.net will consider the viewstate as invalid.

However, in this case, they were not on a web farm so none of this applied.  

Viewstate and viewstate validation use a couple of hidden form fields like __VIEWSTATE and __EVENTVALIDATION.  If the page renders so slowly that the __EVENTVALIDATION field has not rendered by the time someone clicks the button or control that causes the postback, ASP.NET will also believe that the viewstate is invalid and report this.  

I had gotten this far and in my case I also knew that the viewstate used was very large which of course causes the page to take longer to render so I asked them to reduce the viewstate as much as possible and review the page to determine why it took so long to render.  

I still recommend this, but this weekend I also read this article from my colleague Tom that gives more details along with some solutions for the issue and I thought I'd share it with you in case you don't subscribe to his blog.    

 

Later,

Tess

Comments

  • Anonymous
    March 18, 2008
    Aha! I think that's exactly the problem I'm having with a produciton web application I maintain. Thanks so much.

  • Anonymous
    March 18, 2008
    The comment has been removed

  • Anonymous
    March 18, 2008
    The comment has been removed

  • Anonymous
    March 22, 2008
    Tess's If broken it is, fix it you should blog is always good for a read. Tess is an escalation engineer

  • Anonymous
    October 13, 2008
    I saw the same problem on an aspx page with a gridview.  All it was was a web tracker js file, at the bottom of the page, that was not getting downloaded.  I commented out the tracker and all was well. I can't decide if that's a bug in IE, the Framework, or the whole concept of ASP.Net!

  • Anonymous
    January 12, 2009
    Validation of viewstate MAC failed Update: In my case I was NOT using gridview nor DataKeyNames nor slow loading page. Small page with on two buttons, two text boxex, and dropdownlist. Clicking the button1 (add) caused the above error every time. Problem turned out to be the form action property was pointing to  a non-existent page! I used a code-behind method when the Add button is clicked and do not use form.submit. When I cleared the action property of the form, problem went away. My "guess" is that the form submit happens before the code-behind code is processed, since even in debug I would get the error before the breakpoint was hit. Hope this leads to the final answer to this. thanks! Mike.

  • Anonymous
    March 05, 2009
    this worked for me. <pages validateRequest="false" enableEventValidation="false" viewStateEncryptionMode ="Never" />

  • Anonymous
    March 11, 2009
    Mike, you saved me! I had tried every solution I could find for this problem, it turns out just the action property of my form tag was wrong.  Thank you very much!

  • Anonymous
    July 12, 2009
    Hey... i do all the things you mention in your post and disable the view and event state at application level in web.config, but still getting the same error but at a very low rate then previous one. Do smhtin ;)

  • Anonymous
    May 21, 2014
    I notice that it happens when IIS recycles the web application and user has been idle

  • Anonymous
    August 06, 2014
    The comment has been removed