3

In my unhandled exception logging I see this error sporadically through the day on a given page. I don't have any controls that I create programmatically on the page or databind any buttons onto the page.

In my logging I grab the current handler which is where I know the page from and the stacktrace however the stacktrace doesn't give anything meaningful since it just says it boils down to Page.ProcessPostData.

Is there a way that I can log more meaningful data? Like perhaps what it got posted and what it expected to be posted?

I can never reproduce this anywhere.

Chris Marisic
  • 32,487
  • 24
  • 164
  • 258
  • Having a similar problem, and believing this error as one the most irritating errors I've ever encountered – Kasrak Jan 09 '12 at 22:14
  • 1
    @Sypress this error is one of a few phantom errors from ASP.NET webforms that lead me to move to MVC2 and MVC3, and soon MVC4. I've never looked back. – Chris Marisic Jan 10 '12 at 13:38
  • This is the path I'll follow also, But the project which I've made was based on Web Forms, Keep on ;) – Kasrak Jan 11 '12 at 14:41

2 Answers2

3

you can see all of the request's form parameters like this:

if (System.Web.HttpContext.Current != null && System.Web.HttpContext.Current.Request != null) {
    foreach (string key in System.Web.HttpContext.Current.Request.Form.Keys) {
        if (key.IndexOf("__VIEWSTATE") == -1) {
            //key:   key
            //value: System.Web.HttpContext.Current.Request.Form[key]
        }
    }
}
Gabriel McAdams
  • 56,921
  • 12
  • 61
  • 77
  • Can you explain a bit more what i should do with this code to trace the viewstate error? I'm also unable to reproduce to error i see sometimes in my log files. Thanks for sharing! – ThdK Jun 15 '12 at 06:10
2

A common cause of this problem is when a user does not wait for the entire page to render before performing an action that causes a postback. How big is this page? Are users getting impatient?

Another place I see it is with repeater/templated controls with postback controls inside -- like a button inside a repeater's item template -- that incorrectly databind after a postback instead of just once. However, that would consistently fail so seems less likely.

I'm not sure how to get more information from the exception... How are you catching it to begin with? I don't think the Page object itself is instantiated at all when this exception occurs, so you'd probably have to use a custom HttpModule. Can you put a try/catch around ProcessRequest? That should give you access to the Request object and the posted data.

Fenton
  • 241,084
  • 71
  • 387
  • 401
Bryan
  • 8,748
  • 7
  • 41
  • 62
  • The page isn't that large 470K, or 78K for a primed cache (per YSlow). I'm logging the exception in the global.asax Application_Error which lets me pull information from HttpContext.Current.CurrentHandler and Server.GetLastError() which lets me see which page the error came from – Chris Marisic Mar 08 '10 at 14:51
  • You exactly mentioned the real issue I have with one of my projects,And this wasn't mentioned in tons of articles and posts having this error as their subject, thanks man ... – Kasrak Jan 09 '12 at 22:19