Server.Transfer doesn't trigger PreInit event?

Discussion in 'ASP .Net' started by Morgan Cheng, Apr 29, 2007.

  1. Morgan Cheng

    Morgan Cheng Guest

    "Server.Transfer(Request.FilePath);" make server re-evaluate current
    page. In debugger, I found that though the page's OnPreInit is called,
    delegates attached in HttpModule is not executed. Why ASP.NET is
    designed in such a way?

    To make the page executed from scratch, I have to use
    Resposne.Redirect(Request.FilePath), but this will waste a networking
    roundtrip.
     
    Morgan Cheng, Apr 29, 2007
    #1
    1. Advertising

  2. Thats because your already within the bounds of the asp.net request pipeline
    and by using transfer your effectively saying you want to stay within the
    pipeline, all your really doing is transferring the page request to a
    sub-request not intiating a new one. Redirtect takes you out of the asp.net
    pipeline and forces a new request, hence resulting in the behaviour you
    need.

    Regards

    John Timney (MVP)
    http://www.johntimney.com
    http://www.johntimney.com/blog


    "Morgan Cheng" <> wrote in message
    news:...
    > "Server.Transfer(Request.FilePath);" make server re-evaluate current
    > page. In debugger, I found that though the page's OnPreInit is called,
    > delegates attached in HttpModule is not executed. Why ASP.NET is
    > designed in such a way?
    >
    > To make the page executed from scratch, I have to use
    > Resposne.Redirect(Request.FilePath), but this will waste a networking
    > roundtrip.
    >
     
    John Timney \(MVP\), Apr 29, 2007
    #2
    1. Advertising

  3. Morgan Cheng

    Morgan Cheng Guest

    I tried to Server.Transfer to another aspx page in same server. The
    PreInit event is still not triggerred.
    So, we cannot put page related stuff in PreInit handler, right?




    On Apr 29, 9:10 pm, "John Timney \(MVP\)"
    <> wrote:
    > Thats because your already within the bounds of the asp.net request pipeline
    > and by using transfer your effectively saying you want to stay within the
    > pipeline, all your really doing is transferring the page request to a
    > sub-request not intiating a new one. Redirtect takes you out of the asp.net
    > pipeline and forces a new request, hence resulting in the behaviour you
    > need.
    >
    > Regards
    >
    > John Timney (MVP)http://www.johntimney.comhttp://www.johntimney.com/blog
    >
    > "Morgan Cheng" <> wrote in message
    >
    > news:...
    >
    > > "Server.Transfer(Request.FilePath);" make server re-evaluate current
    > > page. In debugger, I found that though the page's OnPreInit is called,
    > > delegates attached in HttpModule is not executed. Why ASP.NET is
    > > designed in such a way?

    >
    > > To make the page executed from scratch, I have to use
    > > Resposne.Redirect(Request.FilePath), but this will waste a networking
    > > roundtrip.
     
    Morgan Cheng, Apr 30, 2007
    #3
  4. No - I dont think you can as you are not re-entering the event pipeline at
    the start of a request

    Regards

    John Timney (MVP)
    http://www.johntimney.com
    http://www.johntimney.com/blog


    "Morgan Cheng" <> wrote in message
    news:...
    >I tried to Server.Transfer to another aspx page in same server. The
    > PreInit event is still not triggerred.
    > So, we cannot put page related stuff in PreInit handler, right?
    >
    >
    >
    >
    > On Apr 29, 9:10 pm, "John Timney \(MVP\)"
    > <> wrote:
    >> Thats because your already within the bounds of the asp.net request
    >> pipeline
    >> and by using transfer your effectively saying you want to stay within the
    >> pipeline, all your really doing is transferring the page request to a
    >> sub-request not intiating a new one. Redirtect takes you out of the
    >> asp.net
    >> pipeline and forces a new request, hence resulting in the behaviour you
    >> need.
    >>
    >> Regards
    >>
    >> John Timney (MVP)http://www.johntimney.comhttp://www.johntimney.com/blog
    >>
    >> "Morgan Cheng" <> wrote in message
    >>
    >> news:...
    >>
    >> > "Server.Transfer(Request.FilePath);" make server re-evaluate current
    >> > page. In debugger, I found that though the page's OnPreInit is called,
    >> > delegates attached in HttpModule is not executed. Why ASP.NET is
    >> > designed in such a way?

    >>
    >> > To make the page executed from scratch, I have to use
    >> > Resposne.Redirect(Request.FilePath), but this will waste a networking
    >> > roundtrip.

    >
    >
     
    John Timney \(MVP\), Apr 30, 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. nail
    Replies:
    7
    Views:
    5,867
    j.selvakumar
    Jun 27, 2007
  2. Marcelo Cabrera

    PreInit event in usercontrol

    Marcelo Cabrera, Dec 22, 2005, in forum: ASP .Net
    Replies:
    9
    Views:
    7,367
    =?Utf-8?B?TWFyY2VsbyBDYWJyZXJh?=
    Jan 19, 2006
  3. shapper

    PreInit event and Master Page

    shapper, Sep 23, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    3,376
    Mark Rae
    Sep 23, 2006
  4. Replies:
    1
    Views:
    7,108
    Mark Rae
    Sep 28, 2006
  5. Rahul
    Replies:
    0
    Views:
    373
    Rahul
    Feb 6, 2007
Loading...

Share This Page