HttpModule Error Handler Stuck In Loop

G

Guest

I use an HttpModule that handles unhandled exceptions from an .aspx.cs page
by logging to a text file, logging to the event viewer's app log, and sending
out an email to the website developer and any interested parties. Finally, a
user friendly page (GenericError.aspx) is Redirected To.

My Page_Load event has no code, so when the page is unavailable, (for
instance, the website is down), an unhandled event is generated and my
HttpModule is called. Everything is executed as listed above, but the
redirection to GenericError.aspx generates another unhandled exception
(because the website is down), and thus we enter into a loop.

I end up with 14000+ email messages, and so does everyone specified in a
web.config list.

The only fix I can see is to put a try/catch block in every Page's Page_Load
event.

Is there some smarter way to handle this?
 
K

Karl Seguin [MVP]

HttpRequest request = Context.Current.Request;
if (string.Compare(request.LocalPath, "/GenericError.aspx", true))
{
Context.Current.Response.Write("An unhandled error occurred");
Context.Current.Response.End();
}
//should be safe to redirect to GenericError.aspx
 
G

Guest

Where do I place this code?

Should it go just before the redirect to GenericError.aspx in the HttpModule?

The problem is redirecting to GenericError.aspx which is in the website that
is down, resulting in firing the HttpModule again.

--
Thank you kindly,

Dan Sikorsky BA, BSCE, MCS


Karl Seguin said:
HttpRequest request = Context.Current.Request;
if (string.Compare(request.LocalPath, "/GenericError.aspx", true))
{
Context.Current.Response.Write("An unhandled error occurred");
Context.Current.Response.End();
}
//should be safe to redirect to GenericError.aspx
 
G

Guest

I see it now. The code goes in at the top of the HttpModule to protect
against being called by the GenericError.aspx, which was already called by
the HttpModule.
--
Thank you kindly,

Dan Sikorsky BA, BSCE, MCS


Karl Seguin said:
HttpRequest request = Context.Current.Request;
if (string.Compare(request.LocalPath, "/GenericError.aspx", true))
{
Context.Current.Response.Write("An unhandled error occurred");
Context.Current.Response.End();
}
//should be safe to redirect to GenericError.aspx
 

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,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top