Tracing invalid postback or callback argument

991 views Asked by At

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.

2

There are 2 answers

1
Gabriel McAdams On BEST ANSWER

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]
        }
    }
}
2
Bryan On

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.