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!
20 comments ↓
Very, very, very nice. Thanks for this, that helped!
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…
Cheers,
Thomas
Hi Andy,
Thanks a lot – you solution with PostBackUrl worked just fine!
—
Alexey
I don’t find this much help if you to create dynamic urls using querystrings formatted based on user text input.
What about autopostback on non button controls such as a textbox?
What if I am using DropDownList control with AutoPostBack = True?
I tried to add PostBackUrl=â€~/samepage.aspx†and it shows validation failure for asp.net control, but does compile and runs!!
Nice and Thanx ::lol:
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! 😀
~Steven
include this one too
enableViewStateMac=”false”
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 ..
Hi, you can try to find answer in this article
http://www.aspnetcafe.com/post/2007/12/Validation-of-viewstate-MAC-failed–The-state-information-is-invalid-for-this-page-and-might-be-corrupted.aspx
Works good for me.
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.
this is very helpful!thanks so much!
@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?
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
Worked for me too
Plz let me know how can i use autopostback with grid?
Thnks!
your PostBackUrl=”~/yoursite.aspx” trick is a life-saver!
You saved my valuable time !
Thanks! Works like a charm!!! 🙂
Leave a Comment