Skip navigation.

Three Negatives Make a... What?All recent postsFree Hotfix Support

Elusive View State Errors

One of the most difficult exceptions to understand is The viewstate is invalid for this page and might be corrupted. There are so many things that lead to it that it's very difficult to get to the bottom of the problem. We've been witnessing these errors for several months now, and since they occur sporadically and only on a live server we've been unable to fully resolve them. I have a guess, though, and a quick fix I've used seems to work.

Normally, an exception stack looks like this:

The viewstate is invalid for this page and might be corrupted.
 at System.Web.UI.Page.LoadPageStateFromPersistenceMedium()
 at System.Web.UI.Page.LoadPageViewState()
 at System.Web.UI.Page.ProcessRequestMain()
 ...

I found KB 829743, Troubleshooting the "View State is invalid" error with ASP.NET, which gives some solid troubleshooting advice, but none of it helped. We don't run a web farm (yet), we can't attach a debugger, nobody can tamper with our view state because we employ long validationKey and validationKey and have the view state encrypted, etc.

I've noticed, though, that the view state became "corrupted" if I browsed to some pages that were, apparently, being cached by Internet Explorer. A one-liner seems to keep the said exception at bay:

HttpContext.Current.Response.Cache.SetExpires (DateTime.Now);

which should prevent page caching and therefore cause view state to be built correctly each time. Time will tell if this fix is "it". I'll post more on this if I find something out.

Comments

Comment permalink 1 James Taylor |
Any word if this fixes the problem? I get a few of these everyday they are very annoying. Seems the more hits I get the more the problem occurs.
Comment permalink 2 Milan Negovan |
Nope, haven't figured it out. The tweaks I described above stopped the flow of view state errors only to a certain degree.
Comment permalink 3 James Taylor |
UGH!!.
I cannot figure out what is going on and they are so random I am not really sure where to start? Well Good luck, I will post if I come up with something. I get about 2 or 3 of these errors a day but they are very frustrating. Causes the user to need to log back in.. what a pain.
Comment permalink 4 Lee Fulford |
Any update on this problem and on the effect of the change in the browser caching? We're getting bitten by this one regularly, and so far the troubleshooting steps haven't helped.
Comment permalink 5 Milan Negovan |
Lee, unfortunately not much progress there. Tweaking caching didn't help much. If you run a search for "view state" on this site you can see how often I deal with view state oddities. :(
Comment permalink 6 Raza Abbas |
I've enabled Caching on my pages, and I've started getting this error lately ...Disabling Cachine is not a very feasible solution for my website. I read somewhere, addition of EnableViewStateMac=false attriibute in web.config does the trick in some cases?
Comment permalink 7 slobo |
The problem is __VIEWSTATE hidden variable. If somebody visitis your page http://www.mypage.com/default.aspx
and the try to do this

http://www.mypage.com/default.aspx?__VIEWSTATE="some_crap"
they will have error message and you will have exception. There is nothing you can do about this.

__VIEWSTATE value is checked every time somebody post page to server. If the value is not correct you got the error.

Emails and Notifications

Would you like to be notified when somebody responds to this post?  Would you like to have these comments emailed to you?

TrackBacks

Sorry, TrackBacks are not allowed.

Submit your comment

Please enter only text since all HTML tags except hyperlinks will be stripped. Hyperlinks will become live links. Any comments with flaming or offensive language will be deleted. Be courteous to other posters. Thank you.

Your name (required):
Your email (optional):
Your site's URL (optional):
Enter this number
Type in the number above:
Comment (required):