Validation of ViewState Mac failed

Probably many of you know this exception:

[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.]

If your page doesn’t load slowly and you are not on a web farm, this little tipp might help you. Most people suggest to add the following attributes to the Page directive:

<pages enableEventValidation=false viewStateEncryptionMode =Never

This is known to be a security risk and in my case it didn’t fix the problem.

I think I found another way to eliminate the Error, add this to your Button which triggers the Postback Event:

   23 PostBackUrl=”~/yoursite.aspx”

Just post it back to the same site explicitly and you should be fine.

Edit: Another discovery, you can use the maxPageSateFieldLength attribute of the Pages element in the web.config. That will split the viewstate across multiple hidden fields if the content length is larger than maxPageSateFieldLength.

Hope that helps!


#1 Jem on 06.28.06 at 10:15 am

Very, very, very nice. Thanks for this, that helped!

#2 Thomas Williams on 07.04.06 at 8:56 am

G’day Andy, thanks for the comments on my blog!

I’m interested, how did setting the PostBackUrl change the page and get rid of the error?

In my case it was hard to test as my problem was that the page was loading slowly, and the “__EVENTVALIDATION” section (at the bottom of the page) was not yet in the transmitted HTML so couldn’t be in the passed POST variables (as I understand it). Hmmm…



#3 Alexey on 08.21.06 at 3:50 pm

Hi Andy,
Thanks a lot – you solution with PostBackUrl worked just fine!


#4 Steve on 09.08.06 at 2:35 pm

I don’t find this much help if you to create dynamic urls using querystrings formatted based on user text input.

#5 Nate on 09.12.06 at 6:57 pm

What about autopostback on non button controls such as a textbox?

#6 KD on 03.06.07 at 11:56 pm

What if I am using DropDownList control with AutoPostBack = True?
I tried to add PostBackUrl=”~/samepage.aspx” and it shows validation failure for control, but does compile and runs!!

#7 Alfred on 03.29.07 at 11:21 am

Nice and Thanx ::lol:

#8 Steven on 07.10.07 at 10:09 pm

After a very frustrating 2 days of trying various things, this fixed my issue with a client. The question I have though is WHY does this fix the problem? Testing locally from inside our network worked fine, testing from outside our network worked fine, but when the client tried to submit the page it would crash with the error mentioned in the article. I can’t even begin to speculate as to why it was actually happening, but thanks for the solution! 😀


#9 rahaman on 08.28.07 at 12:38 pm

include this one too


#10 Amjad on 11.15.07 at 1:26 pm

well, i just changed my master page and that scrwed everything up .. the error jumped it my face with no reasnable Logical explonation !!

what this has to do with the design ?!

cant solve yet anyway ..

#11 John on 12.21.07 at 10:09 am

Hi, you can try to find answer in this article–The-state-information-is-invalid-for-this-page-and-might-be-corrupted.aspx
Works good for me.

#12 Xian on 05.09.08 at 8:35 pm

The simple solution for this problem is (without changing anything in your code) to set the “Check for newer version of stored pages” in the IE Options from “Automatically” to “Every visit to the page”.

The reason this error happens without big changes in your code/page is, that IE shows and sends “chached” data to the server which is not compatible with the real new version of our page and so the “chached” view state is compared/checked against a “new” version on the server.

Just as simple as that. Works for almost any scenario.

#13 angela on 05.20.08 at 5:40 am

this is very helpful!thanks so much!

#14 Brett on 07.07.08 at 11:25 am

@Xian. I wish it was that easy. Getting this error on a WSS 3.0 web application. Works fine on internal network, but as soon as hosted externally throws this error. Tried your workaround, but same error. Anything else?

#15 jim on 08.09.08 at 11:48 pm

ok im not a real wiz on computers, and i was wondering where to find the POSTBACK EVENT and where i can enter that code thing because that error is getting realy anoying

#16 Archana on 08.20.08 at 10:35 am

Worked for me too

#17 Qasim on 09.22.08 at 6:24 am

Plz let me know how can i use autopostback with grid?

#18 Mingkun on 10.26.08 at 7:28 am

your PostBackUrl=”~/yoursite.aspx” trick is a life-saver!

#19 Raja on 01.22.09 at 6:32 am

You saved my valuable time !

#20 Albert on 02.17.09 at 4:53 pm

Thanks! Works like a charm!!! 🙂

Leave a Comment