473,406 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Help with Response.Redirect(URL,True) behavior

We are getting a behavior on a Response.Redirect("SomeUrl", True) that I'm
hoping someone can explain. This all refers to the code snip at the end. By
the way, this is all VB ASP.NET v1.0 code.

So we have the Page_Load event of an ASPX page fire which in the snip you
see calls "SomeMethod". Also you see in Page_Load two Catch statements. The
first is "SpecialException". We created our own extended exception (inherits
from ApplicationException) class to handle certain properties and
functionality not in any standard .NET Exception. The second Catch in
Page_Load traps any other possible exceptions, creates a new
"SpecialException", sets certain properties based on the exception that was
raised and calls "DisplayMethod" to perform needed functions.

Anyway, "SomeMethod" gets called and in there let's say a DivideByZero
exception happens for the sake of an example. In "SomeMethod", the error is
trapped at "Catch ex As Exception". A new SpecialException is created,
populated and then passed to method "DisplayError".

In "DisplayError" you see we handle logging, some other error info massaging
and then finally attempt to do a redirect to our error display page.
Originally we had False in the Redirect method, but since execution would
continue, we'd have other methods finish getting called (some of which made
DB calls), etc. Not wanting to incur all that extra and unnecessary
method/DB calling, we decided to have the current page processing
stop...hence the True for the end response parm. Knowing that raises its own
error, we catch for the ThreadAbortException and "eat" that error...or so we
thought.

It turns out that even though we explicitly trap for that
TreadAbortException error, it still bubbles up the stack. The DivideByZero
error popped in "SomeMethod" and was handled with "Catch ex As Exception"
which then did the "Call DisplayError(New
SpecialException(ex.Message,ex.StackTrace,etc))". In DisplayError we handled
the error, did the Redirect and trapped the ThreadAbortException. From
DisplayError, execution continued back at the "Catch ex As Exception" handler
in "SomeMethod" and then I expected execution to exit from Page_Load
immediately and pick back up at our error display page based on the
Response.Redirect. Well instead, execution picked back up in Page_Load at
its "Catch ex As Exception" error catch and then itself tries to "Call
DisplayError(New SpecialException(ex.Message,ex.StackTrace,etc))".
Furthermore, the "ex" error variable set up there says it is handling the
ThreadAbortException that I thought we already handled in DisplayError.
Fortunately in DisplayError we do some Session checking and see we've already
handled/logged an error so we don't try to do it again and also do not try to
do another Response.Redirect. Execution does finally make it to our error
display page, but I am trying to understand why the "Catch ex As Exception"
in Page_Load is catching the ThreadAbortException that was thrown, and
supposedly already trapped, in DisplayError.

Here's the pseudo-snip:
===============
Public Sub Page_Load()
Try
...
Call SomeMethod
...
Catch sx As SpecialException
Call DisplayError(sx) method to log and show user message
Catch ex As Exception
Call DisplayError(New SpecialException(ex.Message,ex.StackTrace,etc))
End Try
End Sub
Public Sub SomeMethod
Try
...
***Let's just say DivideByZero pops here***
Some Processing
More Processing
...
Catch sx As SpecialException
Call DisplayError(sx) method to log and show user message
Catch ex As Exception
Call DisplayError(New SpecialException(ex.Message,ex.StackTrace,etc))
End Try
End Sub
Public Sub DisplayError(ByRef Exception As SpecialException)
Try
Handle Logging
Perform Other error-massaging
Try
Response.Redirect("OurCustomErrorDisplayPage.aspx" , True)
Catch tae As System.Threading.ThreadAbortException
Eat the Redirect's abort exception here
End Try
Catch ex As Exception
Eat any other possible exception here
End Try
End Sub
============

Thanks in advance.

-Mike
Nov 19 '05 #1
1 2713
Seems I just read the reason why this is happening in online docs for the
ThreadAbortException. Per the docs:
==================
When a call is made to the Abort method to destroy a thread, the common
language runtime throws a ThreadAbortException. ThreadAbortException is a
special exception that can be caught, but it will automatically be raised
again at the end of the catch block. When this exception is raised, the
runtime executes all the finally blocks before killing the thread. Since the
thread can do an unbounded computation in the finally blocks, you must call
the Join method to guarantee that the thread has died. Join is a blocking
call that does not return until the thread actually stops executing.
==================

So it automatically gets raised again at the end of each catch block. Argh!
Any other suggestions for a "clean" way to handle this? Again we want to
avoid all that extra method/DB calling.

Thanks.

-Mike

"MikeM" wrote:
We are getting a behavior on a Response.Redirect("SomeUrl", True) that I'm
hoping someone can explain. This all refers to the code snip at the end. By
the way, this is all VB ASP.NET v1.0 code.


Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: timothy ma and constance lee | last post by:
Sirs How can i use javascript to redirect the url in the drop list box once the event onchnage is triggered?
1
by: VMI | last post by:
I'm a ASP.Net beginner, so please don't laugh :-)) In the button of my initial aspx page, I have this code that sends a URL with parameters my other page: url="ZMResult.aspx?Address1=...
2
by: feng | last post by:
My users who try to access a page before login are redirected to my login page. Then after they successfully login, my login page will redirect the user to the page they intended to go through...
2
by: Dr. Paul Caesar - CoullByte (UK) Limited | last post by:
Hi, I have created a Logout ASP.NET application using Forms Authentication. When a user logs out they get a confirmation page confirming logout and a button to click to return to the homepage....
2
by: porko | last post by:
I want to be able to programmatically log a user in as a guest and redirect them to a different page. Is there any way to do a RedirectFromLoginPage() and explicity specify the page to which the...
6
by: ABC | last post by:
How to redirect URL to new window?
3
by: guillermojco | last post by:
Hi, I've got an ASP.NET page that returns XLS, DOC, PDF and other files from binary fields in a database. The problem is that MS-Excel 2007 shows a security warning when trying to open the...
2
by: nil81 | last post by:
Hello Friends, I want to create a blog for the user that register to my site(for example www.test.com) after that I want to redirect user to www.user.test.com. That is just like...
2
by: =?Utf-8?B?UHJpeWE=?= | last post by:
Hi, I wanted to redirect all requests to my website to a maintenance page for a duration of 3 hours. It is any requests coming to www.abc.com or www.abc.com/index.aspx or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.