Adrian Hara

Working through the .NET maze

  Home  |   Contact  |   Syndication    |   Login
  42 Posts | 0 Stories | 83 Comments | 10 Trackbacks

News

Archives

Post Categories

Today I found myself looking at a strage situation. In our asp.net website we have a mecanism in place for unhandled application exception (yea, all good applications have an unhandled exception or two ;)), like so:

<customErrors mode="On" defaultRedirect="~/Pages/Error/Error.aspx">

            <error statusCode="404" redirect="~/Pages/Error/PageNotFound.aspx"/>

</customErrors>

 

Then there is some code in global.asax's Application_Error, which does a Server.GetLastError() and puts it on the Session, without doing a Server.ClearError() so the exception bubbles up and the asp.net infrastructure redirects the user to the error page specified by customError's defaultRedirect attribute. The error page then takes the exception out of the Session and logs it, also displaying a (somewhat) friendly user message.

 

And it pretty much seemed to work, except when there was an unhandled exception in the login page (that is, the one specified in FormsAuthentication's loginUrl), which seemed to get put on the Session in global.asax, but couldn't be retrieved in the Error page, because...tada... the Session's item count was 0. Somehow, it seemed the Session would just get emptied, somewhere between global.asax's Application_Error and the Error page. After some poking around that rendered no clues or leads, I googled a bit and found this article. It seems that the asp.net infrastructure clears the Session, should an unhandled exception occur which is not “cleared” in Application_Error. Pretty useless if you ask me (also the article author's oppinion). The workaround is to clear the error and redirect to the error page “by hand”, but that defeats the purpose of the whole custom errors mechanism, like so:

 

Session[“exception”] = Server.GetLastError();

Server.ClearError();

Response.Redirect("~/Pages/Error/Error.aspx");

 

Still, I find it strange that for any unhandled exceptions that occur in places other than the Login page, the Session is not cleared and the Error page can read the unhandled exception from the Session just fine. But if an unhandled exception occurs on the Login page, the Session magically goes away.

 

I'd appreciate any thoughts on the matter, while it is pending further investigation...

posted on Monday, June 05, 2006 3:12 PM

Feedback

# re: Beware of <customErrors>' defaultRedirect 12/19/2006 10:20 PM Terry Mc Callister
can't log onto my online banking account

# re: Beware of <customErrors>' defaultRedirect 5/8/2007 4:02 AM andrea melford
how do i get the error of my page

# re: Beware of <customErrors>' defaultRedirect 7/5/2007 7:32 PM Gini
I've got the same problem too. Is the "redirect" the only workaround?

# re: Beware of <customErrors>' defaultRedirect 7/14/2007 7:05 PM fRANCES
runtime error-The current cuastomer error setting prevents the details of the application error from being viewed

# re: Beware of <customErrors>' defaultRedirect 8/22/2007 8:24 AM cindeepaul
how do I get this off so I can go onto myspace and other things

# re: Beware of <customErrors>' defaultRedirect 9/5/2007 11:18 AM ashley
umm how do i fix it?

# re: Beware of <customErrors>' defaultRedirect 12/6/2007 8:38 PM Saddam Hussein
Some nice comments on here. (bank account, myspace) I can understand why it would just poop out the session for only the login page, that would avoid errors caused by unauthorized attempts.
Thanks for the info though, just trying to figure that out would have driven me crazy.

# re: Beware of <customErrors>' defaultRedirect 12/28/2007 3:00 AM # re: Beware of <customErrors>'
how do i get the error of my page

# re: Beware of <customErrors>' defaultRedirect 4/3/2008 9:59 PM cwilson
how do I get thr error off my computer? Ineed to log onto the site that is now locked?? it is called error in application?

# re: Beware of <customErrors>' defaultRedirect 4/11/2008 8:39 PM Torok Gyongyver Rozalia
mode "send to "of"

# re: Beware of <customErrors>' defaultRedirect 6/24/2008 3:11 AM tamara
how to set mode of

# re: Beware of <customErrors>' defaultRedirect 6/28/2008 3:01 AM Vivian Rheams
how do u set your mode to off

# re: Beware of <customErrors>' defaultRedirect 6/30/2008 3:08 AM betty
how do i fix this it will not let me upload pics for my space...

# re: Beware of <customErrors>' defaultRedirect 6/30/2008 5:38 PM indhira
how do i get this off so i can go into myspace and things

# re: Beware of <customErrors>' defaultRedirect 7/16/2008 12:28 AM Lonny Demaree
Can't into body of story on scout.com web page.

# re: Beware of <customErrors>' defaultRedirect 8/4/2008 11:02 PM observer
Google is is your friend but maybe you should contact the owner of the web site you are having problems first.

# re: Beware of <customErrors>' defaultRedirect 8/10/2008 3:04 AM berhane
it is failed to search web sites and it becomes slower and slower

# re: Beware of <customErrors>' defaultRedirect 9/12/2008 5:38 PM Andy Twiss
I have never seen a more random and 'detached from reality' set of responses to a perfectly ordinary programmer's blog entry!

My God, do people really just search for '404' in google and then post on the first blog they come accross???

Apparently, yes they do....

If 'ASP.NET' means nothing to you, then move along, these aren't the answers you're looking for :)

# re: Beware of <customErrors>' defaultRedirect 9/12/2008 6:04 PM Adrian Hara
I wish I could've said it better ;)

# re: Beware of <customErrors>' defaultRedirect 1/3/2009 10:51 PM Bismarck Owusu-Fosu
i cannot access my MRCP on line.This happens often to me, at least once per day and it disturbs my studies.

# re: Beware of <customErrors>' defaultRedirect 1/6/2009 5:36 PM Abdullahi Einte
solivng the problem

# re: Beware of <customErrors>' defaultRedirect 1/9/2009 8:40 AM robin
how do i correct it

# re: Beware of <customErrors>' defaultRedirect 1/11/2009 4:34 AM Lord Templeton the 3rd (Master)
Who in their right mind creates a public blog which features the ability to post comments without first registering?

In any event, I agree with 'Saddam Hussein' (see above).

# re: Beware of <customErrors>' defaultRedirect 3/16/2009 4:16 AM javier dario
porque no habre mi correo


# re: Beware of <customErrors>' defaultRedirect 6/15/2009 10:26 PM Jeanette Matthews
How do I turn the defaultRedirect off so I can view a appilication

# re: Beware of <customErrors>' defaultRedirect 7/2/2009 5:34 PM Tateos
Πώς μπορώ να αποκτήσω thr σφάλμα off υπολογιστή μου; Ineed to log onto the site that is now locked?? Ineed να συνδεθείτε στην τοποθεσία που είναι τώρα κλειδωμένη? it is called error in application? λέγεται σφάλμα στην εφαρμογή του

# re: Beware of <customErrors>' defaultRedirect 7/2/2009 5:38 PM Tateos

Πως μπορώ να πάω σε αυτή, λοιπόν, μπορεί να πάει στο myspace και τα πράγματα

# re: Beware of <customErrors>' defaultRedirect 7/23/2009 12:09 PM jacob
when i click ask glenn a question i keeps coming up with runtime error.what do i do?

# re: Beware of <customErrors>' defaultRedirect 7/23/2009 12:19 PM sue
when i click ask glenn a question i keeps coming up with runtime error.what do i do?


# re: Beware of <customErrors>' defaultRedirect 7/23/2009 12:33 PM jacob
how do i turn off the ask glenn a question runtime error so i can ask him a question

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: