Application_Error优先于Page_Error

时间:2011-07-08 09:26:27

标签: asp.net global-asax

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

谢谢, 的Pawel

P.S。也许是因为被抛出的异常是由于上传过大的文件引起的(我测试过文件上传页面它如何处理比web.config设置更大的文件)并且Page_Error还没有连线?

1 个答案:

答案 0 :(得分:1)

与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.
    }
}
相关问题