Response.Redirect in a Try-Catch

Discussion in 'ASP .Net' started by =?Utf-8?B?VGlt?=, Feb 2, 2004.

  1. Hello,
    I've noticed that sometimes putting a Response.Redirect in a Try-Catch will itself throw an exception due to a threading violation. However, in some cases it works, in others it doesn't, and I can't pre-determine which is which.

    Does anyone know how to ensure that the Response.Redirect doesn't cause threading problems?

    Thanks,
    Tim
    =?Utf-8?B?VGlt?=, Feb 2, 2004
    #1
    1. Advertising

  2. Response.Redirect(False)

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "Tim" <> wrote in message
    news:...
    > Hello,
    > I've noticed that sometimes putting a Response.Redirect in a Try-Catch

    will itself throw an exception due to a threading violation. However, in
    some cases it works, in others it doesn't, and I can't pre-determine which
    is which.
    >
    > Does anyone know how to ensure that the Response.Redirect doesn't cause

    threading problems?
    >
    > Thanks,
    > Tim
    >
    Kevin Spencer, Feb 2, 2004
    #2
    1. Advertising

  3. =?Utf-8?B?VGlt?=

    Marina Guest

    This is because it throws an exception (this is by design). This is
    actually how it manages to stop the current thread - by throwing a special
    kind of exception, which the runtime knows is meant to stop the current
    thread of execution.

    What this means, is that you can't have it in a try catch block.

    "Tim" <> wrote in message
    news:...
    > Hello,
    > I've noticed that sometimes putting a Response.Redirect in a Try-Catch

    will itself throw an exception due to a threading violation. However, in
    some cases it works, in others it doesn't, and I can't pre-determine which
    is which.
    >
    > Does anyone know how to ensure that the Response.Redirect doesn't cause

    threading problems?
    >
    > Thanks,
    > Tim
    >
    Marina, Feb 2, 2004
    #3
  4. > What this means, is that you can't have it in a try catch block.

    Sure you can:

    try
    {
    Response.Redirect(someUrl);
    }
    catch{}

    This is not as elegant as the parameter method of repressing the error, as
    this will cause the exception-handling in .Net to process the error, and
    affect performance, but it will certainly work to repress the error.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "Marina" <> wrote in message
    news:...
    > This is because it throws an exception (this is by design). This is
    > actually how it manages to stop the current thread - by throwing a special
    > kind of exception, which the runtime knows is meant to stop the current
    > thread of execution.
    >
    > What this means, is that you can't have it in a try catch block.
    >
    > "Tim" <> wrote in message
    > news:...
    > > Hello,
    > > I've noticed that sometimes putting a Response.Redirect in a Try-Catch

    > will itself throw an exception due to a threading violation. However, in
    > some cases it works, in others it doesn't, and I can't pre-determine which
    > is which.
    > >
    > > Does anyone know how to ensure that the Response.Redirect doesn't cause

    > threading problems?
    > >
    > > Thanks,
    > > Tim
    > >

    >
    >
    Kevin Spencer, Feb 2, 2004
    #4
  5. Thanks... I looked at the second overload method for Response.Redirect
    why would you use false instead of true (you want the execution to stop in order to prevent an error?)
    would you just code it like so:

    try {
    //do stuff...
    } catch {
    Response.Redirect('myPage.aspx', true);
    }

    Thanks
    =?Utf-8?B?VGlt?=, Feb 3, 2004
    #5
  6. Sorry about leaving the URL parameter out of my example! You set it to
    false, because if you set it to true it will cause an exception. I realize
    the documentation is a bit ambiguous regarding this, but that's what works.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "Tim" <> wrote in message
    news:...
    > Thanks... I looked at the second overload method for Response.Redirect
    > why would you use false instead of true (you want the execution to stop in

    order to prevent an error?)
    > would you just code it like so:
    >
    > try {
    > //do stuff...
    > } catch {
    > Response.Redirect('myPage.aspx', true);
    > }
    >
    > Thanks
    Kevin Spencer, Feb 3, 2004
    #6
    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:
    7,975
    Charles A. Lackman
    Jan 11, 2006
  2. =?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,220
    Srowe1975
    Oct 15, 2008
  3. bienwell
    Replies:
    4
    Views:
    3,717
    bienwell
    May 27, 2005
  4. Sal
    Replies:
    1
    Views:
    379
  5. Ron Howard
    Replies:
    2
    Views:
    509
    Ron Howard
    Aug 11, 2004
Loading...

Share This Page