Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When Using Server.Transfer is the entire Asp.Net life-cycle executed again?

Tags:

c#

asp.net

I understand that Server.Transfer doesn't make a round trip back to the requesting client.

What I haven't been able to learn is if control is simply passed directly to the new request handler you're transferring to or if or if the entire request life-cycle is executed again.

I assume the entire life-cycle is executed again using the transfer URL but wanted to verify this was the case.

like image 453
Mark Rucker Avatar asked Oct 07 '22 10:10

Mark Rucker


1 Answers

Here is what I found through experimentation.

When using Server.Transfer the entire request life cycle is not ran again.

If you write your own Module, hook it into the request life cycle, and call Server.Transfer from that module the rest of the request life cycle will be skipped and the page life cycle will begin immediately.

After completing the transfer page life cycle the request life cycle picks back up with its tear-down events. Note, the HtppContext in for the tear-down events will be the original one you transferred from. That is, the URL and QueryString values will be the same as the original request and not be the URL and QueryString values for the page you transferred to.

Server.Transfer does modify the HttpContext.Request object to contain the new URL and QueryString information during the page life cycle for the page you transferred to.

If you transfer to a resource that is not a page but is text based (e.g. something.xml) the content of that page will be returned exactly as is with its encoding set to text/html.

If you transfer to a resource that is not a page and is not text based (e.g. something.pdf) then an HttpException error will be thrown. This happens even if you have defined a custom Handler for this resource.

like image 52
Mark Rucker Avatar answered Oct 13 '22 11:10

Mark Rucker