Server.Transfer doesn't trigger PreInit event?

  • Thread starter Thread starter Morgan Cheng
  • Start date Start date
M

Morgan Cheng

"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.
 
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
 
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?
 
Back
Top