Infinite loop when using Server.Transfer

Discussion in 'ASP .Net' started by Alexander Bosch, Oct 31, 2004.

  1. Hi,
    I'm sorry for the double posting, but I haven't got any solution for this
    and I'm still puzzled by this KB
    http://support.microsoft.com/default.aspx?scid=kb;en-us;839521
    that's saying this was solved on Service Pack 1 of .NET 1.1 when it didn't.
    Could any one give me a hand on this?
    Just give it a try, create a new web project, put a button on webForm1.aspx
    and on the event handler put this code: Server.Transfer("webForm1.aspx ",
    true);

    you'll see you get the same Exception:
    An unhandled exception of type 'System.StackOverflowException' occurred in
    mscorlib.dll

    that the KB is saying was solved.

    If you try this without the Service Pack everything works normally.
    Any help would be appreciated.
    thanks,
    Alexander
     
    Alexander Bosch, Oct 31, 2004
    #1
    1. Advertising

  2. Hi Alexander,

    I've posted my reply in the former thread regarding on the same issue. For
    your convenience , I'll repaste my reply here. Also, if you feel it
    convenient that we continue to discuss in one of the two threads, please
    feel free to followup in either one. Thanks.


    #######################################3
    Hi Alexander,

    Thanks for your posting. As for the problem you mentioned, I've checked the
    kb article, seems the kb article haven't explained the cause detailedly.
    Also, I'm feel strange that the kb said the problem may resolved after the
    installed the latest .net 1.1 sp , but you're still suffering it after that
    ,yes?

    Anyway, I'll explain the root cause of the problem first:
    =====================================
    Cause: This is due to a change in behavior of the Server.Transfer method.
    From .NET
    version 1.0 to 1.1 the Server.Transfer behaves differently. In version 1.0,
    Server.Transfer preserves the Forms collection and the QueryString
    property, and
    considers the Transfer method as part of a postback. Therefore, the
    Page.IsPostBack
    property is set to true. Initially version 1.1, the transfer is not
    considered part
    of the postback and Page.IsPostBack is set to false even if Server.Transfer
    transfers back to itself. With the fix from 821758, the functionality from
    v1.0 was
    added to v1.1 - that is, the IsPostBack is set to true and the forms
    collection is
    preserved by default. If a page transfers to itself it will be considered a
    postback, however, with such a postback the page object is retained so when
    the
    postback occurs the event that trigger the server.transfer will be fired
    again. If
    this postback event is not trapped in the event the Server.Transfer method
    will be
    executed again. On all subsequent transfers the same process will occur
    cauing the
    page to transfer to itself repeatedly until all stack space is used and the
    Stack
    Overflow exception is genrated.
    ===========================================

    Also, here are some available resolutions against the cause of the problem:

    Using the false attribute with Server.Transfer will resolve the issue, for
    example:

    Server.Transfer('selfpage.aspx',false);

    however, this'll make on a transfer to itself the page will no longer have
    access to the Forms
    collection. If maintaining the Forms collection is required as part of the
    "postback", some additional code should be added to the event triggering
    the Server.Transfer
    call to check for an IsPostBack or other session variable indicating that
    the
    transfer has taken place and should not execute again. For example, either
    of the
    following code would keep the Server.Transfer from executing on subsequent
    postbacks:
    Option One: Check for postback
    If (!IsPostBack)
    {
    Server.Transfer("webform1.aspx", true)
    {
    Option Two: Set a page item to use as a flag
    if (Context.Items["Transfered"] == null)
    {
    Context.Items["Transfered"] = new object();
    Server.Transfer("foo.aspx", true);
    }


    Hope these helps. Also, if you have anything unclear, please feel free to
    post here. Thanks.

    #################################33
     
    Steven Cheng[MSFT], Nov 1, 2004
    #2
    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. Alexander Bosch

    Infinite loop when using Server.Transfer

    Alexander Bosch, Oct 28, 2004, in forum: ASP .Net
    Replies:
    11
    Views:
    916
    Steven Cheng[MSFT]
    Nov 10, 2004
  2. Replies:
    5
    Views:
    626
    benben
    Jan 31, 2006
  3. Hukkky

    Server/Client infinite loop problem

    Hukkky, Oct 24, 2008, in forum: C Programming
    Replies:
    3
    Views:
    440
    Keith Thompson
    Oct 25, 2008
  4. Jim
    Replies:
    1
    Views:
    995
    Aaron Bertrand - MVP
    Jan 28, 2004
  5. Isaac Won
    Replies:
    9
    Views:
    460
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page