How to fix ViewStateException Invalid ViewState?

Usually you don't see Invalid ViewState exception unless you implement some kind of ASP.NET error logger in Global.asax.

Error usually states something like this:

Exception: System.Web.HttpException: The state information is invalid for this page and might be corrupted. ---> System.Web.UI.ViewStateException: Invalid viewstate.

Those errors are usually generated by some automatic submission form engines. Comments and contact forms are mostly effected by this exception. End user never sees those errors, so invalid viewstate errors don't have any value for your error logger. Let's bypass them:

if (ex is HttpException && ex.InnerException is ViewStateException)
{
    _app.Response.Redirect(_app.Request.Url.AbsoluteUri)                
    return
}

See my error logger article for further details.

Wednesday, June 23, 2010 | Comments (2) | Add Comment

Comments

Gravatar

Re:How to fix ViewStateException Invalid ViewState?

thanks for the help.

7/3/2010 10:43:15 AM | by Surge
Gravatar

Re:How to fix ViewStateException Invalid ViewState?

Hi,

What is the _app. ?

thanks.

8/18/2010 6:47:07 AM | by selcuk yazar
Gravatar

Sorry,
I took this if statement from my logger code. _app is HttpContext.Current.ApplicationInstance.

New Comment

Your Name:
Email (for internal use only):
Subject:
Comment:
 
Code above:

Categories

Recent Tweets

  • Creating a Microsoft .NET Compact Framework-based Animation Control http://t.co/P92rCZ4
  • Now you can jailbrake your iphone from browser: http://bit.ly/91Nm7S. It is legal, but voids your iPhone warranty.
  • iPhone jailbreaking and Android rooting get DMCA exemption http://bit.ly/bCmEEA
  • Here is excellent tool for development of JQuery scripts, it is called jsshell: http://bit.ly/72wsQz. It is Google Chrome extension.

Valid XHTML 1.0 Transitional