Geeks With Blogs

@adrianhara
  • adrianhara @DellCares hey Dell, I bought a monitor from a reseller that went bankrupt and now the monitor died (still under warranty)...what can I do? about 413 days ago
  • adrianhara @nlaplante heh, i implemented something myself yesterday and submitted a pull request...looking forward to comparing the two about 419 days ago
  • adrianhara @nlaplante hey, is there a way to load "self-contained" info window content for the angularmap directive? (load template html+controller)? about 420 days ago
  • adrianhara well lol, apparently Microsoft customer satisfaction surveys expire after a week or so...does MS think customers forget that easily? :) about 481 days ago
  • adrianhara LucasArts is being shut down, but their amazing achievements will live forever...oh and frack Mickey Mouse! about 482 days ago
  • adrianhara argh! can't get anything to show up in @jira's "reviews" tab :( application links are set up, source tab is populated, reviews tab not #cry about 483 days ago

News

Locations of visitors to this page




Adrian Hara Working through the .NET maze

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 5, 2006 3:12 PM | Back to top


Comments on this post: Beware of ' defaultRedirect

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
can't log onto my online banking account
Left by Terry Mc Callister on Dec 19, 2006 10:20 PM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
how do i get the error of my page
Left by andrea melford on May 08, 2007 4:02 AM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
I've got the same problem too. Is the "redirect" the only workaround?
Left by Gini on Jul 05, 2007 7:32 PM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
runtime error-The current cuastomer error setting prevents the details of the application error from being viewed
Left by fRANCES on Jul 14, 2007 7:05 PM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
how do I get this off so I can go onto myspace and other things
Left by cindeepaul on Aug 22, 2007 8:24 AM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
umm how do i fix it?
Left by ashley on Sep 05, 2007 11:18 AM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
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.
Left by Saddam Hussein on Dec 06, 2007 8:38 PM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
how do i get the error of my page
Left by # re: Beware of <customErrors>' on Dec 28, 2007 3:00 AM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
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?
Left by cwilson on Apr 03, 2008 9:59 PM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
mode "send to "of"
Left by Torok Gyongyver Rozalia on Apr 11, 2008 8:39 PM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
how to set mode of
Left by tamara on Jun 24, 2008 3:11 AM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
how do u set your mode to off
Left by Vivian Rheams on Jun 28, 2008 3:01 AM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
how do i fix this it will not let me upload pics for my space...
Left by betty on Jun 30, 2008 3:08 AM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
how do i get this off so i can go into myspace and things
Left by indhira on Jun 30, 2008 5:38 PM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
Can't into body of story on scout.com web page.
Left by Lonny Demaree on Jul 16, 2008 12:28 AM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
Google is is your friend but maybe you should contact the owner of the web site you are having problems first.
Left by observer on Aug 04, 2008 11:02 PM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
it is failed to search web sites and it becomes slower and slower
Left by berhane on Aug 10, 2008 3:04 AM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
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 :)
Left by Andy Twiss on Sep 12, 2008 5:38 PM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
I wish I could've said it better ;)
Left by Adrian Hara on Sep 12, 2008 6:04 PM

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

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
solivng the problem
Left by Abdullahi Einte on Jan 06, 2009 5:36 PM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
how do i correct it
Left by robin on Jan 09, 2009 8:40 AM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
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).
Left by Lord Templeton the 3rd (Master) on Jan 11, 2009 4:34 AM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
porque no habre mi correo
Left by javier dario on Mar 16, 2009 4:16 AM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
How do I turn the defaultRedirect off so I can view a appilication
Left by Jeanette Matthews on Jun 15, 2009 10:26 PM

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

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...

Πως μπορώ να πάω σε αυτή, λοιπόν, μπορεί να πάει στο myspace και τα πράγματα
Left by Tateos on Jul 02, 2009 5:38 PM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
when i click ask glenn a question i keeps coming up with runtime error.what do i do?
Left by jacob on Jul 23, 2009 12:09 PM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
when i click ask glenn a question i keeps coming up with runtime error.what do i do?
Left by sue on Jul 23, 2009 12:19 PM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
how do i turn off the ask glenn a question runtime error so i can ask him a question
Left by jacob on Jul 23, 2009 12:33 PM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
i need to open this webside for my official purpose.
Left by md mustaqu ahamed on Jan 26, 2010 4:15 AM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
how do I turn off the ask glenn a question runtime error so I can ask him aquestion
Left by ٍsamia Ibrahim Afifi on Feb 04, 2010 2:20 AM

# re: Beware of <customErrors>' defaultRedirect
Requesting Gravatar...
After reading the comments, I am feeling strangely compelled to add my own comment of "how i i send to of i want see lolcats get error"

Oh dear, now anybody searching for lolcats will also end up on this page...

Anyway, I am experiencing the same problem, but I'm not getting it in the login page. Everything works fine until I get a 404. It handles it fine once, but after that, Session["exception"] = Server.GetLastError() throws a "Session state is not available in this context" for all errors. I have to stop and start my app to fix it.

Does this cast any light on the problem?
Left by Shrog on Feb 19, 2010 2:36 AM

Your comment:
 (will show your gravatar)
 


Copyright © Adrian Hara | Powered by: GeeksWithBlogs.net | Join free