处理“无效的回发或回调参数”错误

发布于 2025-01-08 01:54:25 字数 610 浏览 5 评论 0原文

我们的网站上有错误报告,因此每当发生错误时我们都会通过电子邮件收到通知,并且这种特定错误会定期发生。我想处理它只是因为它很烦人。在我们的例子中,其主要原因是机器人访问我们的网站并做任何他们正在做的事情来修改页面数据。我正在考虑将下面的代码实现到 Global.asax 中,但我想知道是否有更好的方法来处理它,或者是否有一个我不应该这样做的原因(除了我不会这样做的事实之外)被通知潜在的合法错误),然后让它出错并将用户重定向到我们的错误页面。

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);
    }
}

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);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的呼吸 2025-01-15 01:54:25

我不会只是接受这个错误,因为正如您所说,它可能掩盖您网站上弹出的真正问题。我认为更好的方法是调整错误报告的配置。
我不知道您正在使用什么报告基础设施,但您可能不希望网站上发生的每个错误都收到电子邮件(如果它是一个大型网站,可能会出现严重的信噪比问题)。有没有办法过滤您的报告,以便“这些进入日志文件”,“这些致命/重要的进入电子邮件”等等......?

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....?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文