Response.Redirect issue with multiple threads.

Discussion in 'ASP .Net' started by =?Utf-8?B?bWloa2VsdHQ=?=, Oct 8, 2007.

  1. 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
     
    =?Utf-8?B?bWloa2VsdHQ=?=, Oct 8, 2007
    #1
    1. Advertising

  2. 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

    "mihkeltt" <> wrote in message
    news:...
    > 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
     
    Kevin Spencer, Oct 8, 2007
    #2
    1. Advertising

  3. 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.

    "mihkeltt" wrote:

    > 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
     
    =?Utf-8?B?bWloa2VsdHQ=?=, Oct 8, 2007
    #3
  4. =?Utf-8?B?bWloa2VsdHQ=?=

    bruce barker Guest

    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)

    mihkeltt wrote:
    > 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
     
    bruce barker, Oct 8, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman
    Replies:
    2
    Views:
    8,073
    Charles A. Lackman
    Jan 11, 2006
  2. Matthew Wieder

    Response.Write and Response.Redirect

    Matthew Wieder, Jul 17, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    748
    Kevin Spencer
    Jul 17, 2003
  3. =?Utf-8?B?VHJveQ==?=

    Response.redirect does not redirect from .aspx page

    =?Utf-8?B?VHJveQ==?=, Oct 18, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    5,332
    Srowe1975
    Oct 15, 2008
  4. Sal
    Replies:
    1
    Views:
    918
  5. Ron Howard
    Replies:
    2
    Views:
    560
    Ron Howard
    Aug 11, 2004
Loading...

Share This Page