Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tracing invalid postback or callback argument

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.

like image 435
Chris Marisic Avatar asked Aug 16 '26 03:08

Chris Marisic


2 Answers

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]
        }
    }
}
like image 166
Gabriel McAdams Avatar answered Aug 18 '26 17:08

Gabriel McAdams


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.

like image 20
Bryan Avatar answered Aug 18 '26 17:08

Bryan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!