Handling errors thrown in Application_Error()

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
 
G

George Ter-Saakov

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

Phil Johnson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top