Handling errors thrown in Application_Error()

  • Thread starter Thread starter Phil Johnson
  • Start date Start date
P

Phil Johnson

I have a web app that handles errors in the Gloabal.ascx's Application_Error().

It does some logging etc in there and if it throws an error, I want the app
to display a static html splash page rather than a yellow screen asp.net
error.

I have tried setting the custom error page and also a try catch in the
application_error with a server.transfer in the catch but it always seems to
go to a yellow screen asp.net error page (without any details if I set
customErrors to On, but it doesn't go to the page I have set as the custom
error page)

Any ideas how I can get it to show that page if it throws an error in
Application_Error?

--
Regards,

Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com
 
Do you call HttpContext.ClearError at the end of processing?

Second thing I would look at if the Application_Error throws exception as
well....


So theoretically your code should be something like this

protected void Application_Error(Object sender, EventArgs e)
{
try
{
.....blablabla
}
finally
{
Context.ClearError();
Response.Redirect("myerrorpage.htm"); //Or transfer.
}
catch(Exception e)
{
// do not know what to do. we stuck with exceptions.
}
}

George.
 
Hi George,

Thanks for the response, your suggestion would work, and when I changed to
use it it did help me resolve my underlying issue and switch back to the
declarative web.config approach....

It turned out my error page was only available to logged on users, which was
why the customErrors page was never being displayed.

The order now is that when an error occurs it goes into application_error in
global.asax. If an error occurrs in the handling, the page detailed in the
customErrors in the web.config is displayed, which is what I initally hoped
would happen.

--
Regards,

Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com
 
Back
Top