We have error reporting on our website so we’re notified via e-mail whenever errors occur, and this particular error occurs on a somewhat regular basis. I’d like to handle it simply because it’s annoying. The main cause of it, in our case, is from bots hitting our site and doing whatever it is they’re doing to modify the page data. I’m considering implementing the code below into the Global.asax, but I’m wondering if there’s a better way to handle it, or if there’s a reason I shouldn’t being doing this (aside from the fact that I won’t be notified of potentially legitimate errors) and just letting it error and redirect the user to our error page.
void Application_Error(object sender, EventArgs e)
{
var exception = Server.GetLastError();
if (exception is HttpUnhandledException && exception.InnerException.ToString().Contains("Invalid postback or callback argument."))
{
Server.ClearError();
Response.Redirect(HttpContext.Current.Request.Url.AbsolutePath);
}
}
I wouldn’t just swallow the error because as you said, it could mask a real problem that pops up on your site. I think the better approach would be to adjust the configuration of your error reporting.
I don’t know what reporting infrastructure you are using, but you probably don’t want an email for every error that occurs on your site (if it’s a large site that could be a serious signal to noise issue). Is there a way to filter your reporting such that “these go to the log file”, “these fatal/important ones go to email” etc….?