473,399 Members | 4,254 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,399 software developers and data experts.

Response.Redirect gens ThreadAbortException that's either not being caught or thrown a second time.

I have the following situation: I was getting intermittent errors using
Reponse.Redirct("url", true) and was trying to catch the
ThreadAbortException, but it was not staying caught and was showing up again
where my code wasnt expecting it. I'm not sure what was causing it. The
catch block in RedirectPage is supposed to quash the ThreadAbortException
but it not only shows up there, but also in the outer catch block will catch
it as well. It should not show up in both places.

For example
try 'Outer
'Do stuff
'want to catch an exception on a specific action
try
Throw new Exception("test")
catch ex as Exception
RedirectPage("Error.aspx")
End Try

catch tex as TreadAbortException
'This should never fire as the RedirectPage function catches it. But
it's showing up after the RedirectPage catches a ThreadAbortException
already
catch ex as exception
'should be only something not handled previously.
End Try
Public sub RedirectPage(url as string)
Dim strMsg As String
Try
Response.Redirect(url, TRUE)
Catch tex As Threading.ThreadAbortException ' this is SUPPOSED to
catch the threadAbort if true is passed in, but it doesnt always
strMsg = tex.Message
Catch ex As Exception
strMsg = ex.Message
End Try

End Sub
Nov 19 '05 #1
1 2367
I am not surprised you are bubbling up Response.Redirect errors. There is an
easy way around it.

In your catches set some booleans instead of Response.Redirect. You can then
create an if block to determine where to send the person:

If (pageInError) Then
Response.Redirect("Error.aspx")
Else If ....

etc.

Do not have any work after this block. You should have already answered the
question of whether you are redirecting and where by this time.

Why the error? It is simple. You are sending out a Response.Redirect to the
client, which makes the client request the new page. Any code after the
redirect should not be run, so the thread answering THIS PARTICULAR request
has to abort. If the last action is the Redirect, you get around this issue.
It is all in the ordering.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"Eric" wrote:
I have the following situation: I was getting intermittent errors using
Reponse.Redirct("url", true) and was trying to catch the
ThreadAbortException, but it was not staying caught and was showing up again
where my code wasnt expecting it. I'm not sure what was causing it. The
catch block in RedirectPage is supposed to quash the ThreadAbortException
but it not only shows up there, but also in the outer catch block will catch
it as well. It should not show up in both places.

For example
try 'Outer
'Do stuff
'want to catch an exception on a specific action
try
Throw new Exception("test")
catch ex as Exception
RedirectPage("Error.aspx")
End Try

catch tex as TreadAbortException
'This should never fire as the RedirectPage function catches it. But
it's showing up after the RedirectPage catches a ThreadAbortException
already
catch ex as exception
'should be only something not handled previously.
End Try
Public sub RedirectPage(url as string)
Dim strMsg As String
Try
Response.Redirect(url, TRUE)
Catch tex As Threading.ThreadAbortException ' this is SUPPOSED to
catch the threadAbort if true is passed in, but it doesnt always
strMsg = tex.Message
Catch ex As Exception
strMsg = ex.Message
End Try

End Sub

Nov 19 '05 #2

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

Similar topics

1
by: Axel Dahmen | last post by:
Hi, I'm wondering what is Response.Redirect(string) equivalent to: Response.Redirect(string,true) - or - Response.Redirect(string,false) ? The MSDN Library is unclear on this.
4
by: csn | last post by:
Is it possible to have a Response.Redirect in Global.asax in the Application_Start and Session_Start events? We have code in both events, with try-catch blocks, and if an exception is caught, we...
1
by: MikeM | last post by:
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. ...
9
by: postings | last post by:
Just a quick question... When I do a "response.redirect" from a source webpage to a destination webpage, does the code on the source webpage carry on executing unless I put a "response.end"...
3
by: Marc Hoeijmans | last post by:
Hello, I have a problem with the Response.Redirect. The redirect is working for some users for other useres it is not working. We all use the same browser. I have coded the Response.Redirect after...
5
by: Henrik Stidsen | last post by:
I have implemented a log-system for exceptions in an ASP.NET application using the Application_Error event in Global.asax. ThreadAbortExceptions gets thrown everytime Response.Redirect is being...
6
by: foolmelon | last post by:
If a childThread is in the middle of a catch block and handling an exception caught, the main thread calls childThread.Abort(). At that time a ThreadAbortException is thrown in the childThread. ...
3
by: =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?= | last post by:
Hi, I am running a web service which sometimes throws exceptions. I have a lot of error trapping within the web service, but I have missed the current problem. I am working on the current issue,...
5
by: Doug | last post by:
In the code below, I am trying to go from one asp page to another: For Each tripToAccept As String In tripsToAccept.Split("/"c) dataManager.UpdateTripDetail("Accept", CInt(tripToAccept),...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.