Server.Transfer doesn't trigger PreInit event?

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

John Timney \(MVP\)

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
 
M

Morgan Cheng

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top