Application_Error 优先于 Page_Error

发布于 2024-11-19 02:22:40 字数 247 浏览 1 评论 0原文

我在页面中有 Page_Error 方法引发错误,在 global.asax 中有 Application_Error 。当Page抛出异常时,执行的例程是Application_Error。但对于那个特定页面,我希望在 Page_Error 中进行不同的处理。有什么办法可以实现吗?

谢谢, 帕维尔

​也许是因为上传的文件太大而引发异常(我测试了文件上传页面如何处理大于 web.config 设置的文件)并且 Page_Error 尚未连接?

I have both Page_Error method in page that raises error, and Application_Error in global.asax. When Page throws exception, executed routine is Application_Error. But for that one particular page I would like to have different handling in Page_Error. Is there any way to achieve it?

Thanks,
Pawel

P.S. Perhaps it is because exception being thrown is caused by too large file being uploaded (I tested file upload page how it handles files bigger then web.config setting) and Page_Error is not yet wired?

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

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

发布评论

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

评论(1

孤者何惧 2024-11-26 02:22:40

从相同的 Page_Error 函数中,您可以检查页面,如果是您看到的页面,则您有不同的行为。

if( HttpContext.Current.Request.Path.EndsWith("YourFileName.axd", StringComparison.InvariantCultureIgnoreCase))
{
   // the diferent way
}
else
{

}

下一个方法是从具有不同行为的页面内部。

public override void ProcessRequest(HttpContext context)
{
    try
    {
        base.ProcessRequest(context);
    }
    catch (Exception x)
    {
        // here is the different, since you catch here is not move to the Page_Error
        // except is a code error... in any case you can do an extra error clear.
    }
}

From the same the function of Page_Error you can check for the page and if is the one you look you have diferent behavior.

if( HttpContext.Current.Request.Path.EndsWith("YourFileName.axd", StringComparison.InvariantCultureIgnoreCase))
{
   // the diferent way
}
else
{

}

The next way is from inside the page with the diferent behavior.

public override void ProcessRequest(HttpContext context)
{
    try
    {
        base.ProcessRequest(context);
    }
    catch (Exception x)
    {
        // here is the different, since you catch here is not move to the Page_Error
        // except is a code error... in any case you can do an extra error clear.
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文