dragonfly
dragonfly

Reputation: 17773

Application_Error takes precedence over 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?

Upvotes: 0

Views: 1145

Answers (1)

Aristos
Aristos

Reputation: 66641

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

Upvotes: 1

Related Questions