Response.Redirect vs Server.Transfer

  • Thread starter Thread starter Harsh Thakur
  • Start date Start date
H

Harsh Thakur

Hi,

I'd like to know the performance related differences between
Response.Redirect and Server.Transfer.
I'd like to redirect the user to a different page.
I can either do a Response.Redirect("URL") or a Server.Transfer("URL").
So I'd like to find out which is more efficient/better.
Can anyone please tell me or give any pointers to links on the web?

Thanks & Regards
Harsh Thakur
 
From an efficiency perspective, there's no doubt that Server.Transfer is
better.
Response.Redirect requires a round trip back to the browser, while this is
unnecessary with Server.Transfer.
About the only downside to Server.Transfer is that, because all the action
stays on the server, the browser is not aware that the page has changed and
the original page's URL is still displayed in the browser. This can also
cause issues with the browser back button since the browser sees it as the
same page. If you can live with that then definitely go with
Server.Transfer.
 
Hi Steve,

Thanks for your response.
Now I feel much better about using Server.Transfer.

I have one more query though.
What happens to the Page object which invoked the Server.Transfer?
Lets say PageOne called Server.Transfer("PageTwo").
I know PageOne stays alive for a while longer.
When is it destroyed? Is it GC'd just like any other object?
I'd like to know this because it might mean extra memory load for the
server.

Actually, instead of using query strings, we expose a Get method on PageOne
and then call that method in the Page_Load of PageTwo.

Regards
Harsh Thakur
 
The Page object is transferred also in the HttpContext. It is GC'd like any
other object. As for the memory load, I believe using Server.Transfer would
be more optimal, as it doesn't require the processing of 2 Requests.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Neither a follower nor a lender be.
 
Back
Top