Response.Redirect issue with multiple threads.

G

Guest

Hi,

i am one of those many people who has stumbled upon the
ThreadAbortException. I completely understand the reason why it always throws
this exception. The reason is to stop executing any client code and assign
control over back to the httpapplication.

My situation is the following: i run my client code in a PageAsyncTask. This
means the client code runs in a thread (i call it the 2nd thread) other than
the one which the request started in (i call it the 1st thread). When i do a
Response.Redirect in the 1st thread, everything works as expected as the
redirect aborts the first thread and control goes over to the httpapplication
thread. now things get worse once i try to do a redirect from the 2nd
thread. then the redirect internally aborts the second thread, which is now
what should happen. I've tried every possible solution available on the web,
but none are viable. As there is a third party component used in client code
which calls Response.Redirect directly from withing using
HttpContext.Current.Response.Redirect, and this happens in the 2nd thread,
thus givig the ThreadAbortException when ending the PageAsyncTask. And no, i
cannot use Response.Redirect(URL, false). I've tried several solutions with
this call combined with CompleteRequest.

for example, none of the solutions are completely acceptable for me:
http://www.c6software.com/articles/ThreadAbortException.aspx

My questions are:
1) is it impossible to use Response.Redirect as is from an async task or
from a thread other than the original request thread? It should be a fairly
common situation where redirect is required in a multithreaded web
application, or am i wrong?
2) is there an event of some sort to which i can attatch my own redirect and
response end logic?
3) any solution to this one?:) as i'm quite desperate and deadline is
closing in.


thnx,
Mihkel
 
K

Kevin Spencer

It sounds like your problem is coming from calling Response.Redirect twice.
This method creates an HTTP redirect header which is sent back to the client
in the HTTP Response. The client then requests the URL of the redirect
header. I'm not sure what would happen by trying to add the header twice,
particularly after the responding thread is aborted, but apparently the
ASP.Net engine doesn't like it.

--
HTH,

Kevin Spencer
Microsoft MVP

DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
G

Guest

I've done some more tests and what i've discovered is:

1) when manually creating a new thread and running it, and inside that
thread calling redirect(url) - it works fine.
2) i created a really stripped down version of the original site using just
the pageasynctask part and calling redirect(url) method in the async delegate
invocation - it gives the thread being aborted exception.

maybe this insight gives some more food of thought.
 
B

bruce barker

Response.Redirect is pretty simple. it set the status header to 30 and
the url. optionally it kills the current thread to prevent anymore
output via httpresponse. when using async tasks you really should not
kill them as a normal process.

in your case its pretty simple. in onerror catch the abort, and check if
the status is set to redirect. if so, just do a response.end().

also not sure why you are doing an async task when it needs access to
the response object. also if you only have one task the only gain is
returning a request thread to the pool early.

-- bruce (sqlwork.com)
 

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,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top