Reputation: 10672
What is the difference between Server.Transfer
and Response.Redirect
?
Upvotes: 3
Views: 2518
Reputation: 17655
Response.Redirect should be used :
if we don't care about causing additional roundtrips to the server on each request
if we do not need to preserve Query String and Form Variables from the original request
if we want our users to be able to see the new redirected URL where he is redirected in his browser
Response.Redirect is more user-friendly, as the site visitor can
bookmark the page that they are redirected to.
Server.Transfer should be used :
Upvotes: 0
Reputation: 3340
Response.Redirect sends a '302 Moved Temporarily' response to the client, the client browser will then issue a request to that location.
Server.Transfer transfers the control from one page to the other on the server side, so the original Request and Response buffer streams remain as they are at the point the transfer is done.
This means that Response.Redirect requires a round trip to the client but a Server.Transfer does not. The other difference is that the Server.Transfer appears to the browser as the original url... e.g. consider Page1.aspx does a server.transfer to page2.aspx, In this case Page1.aspx shows in the address bar even though they are actually being shown Page2.aspx. If instead Page1.aspx did a Response.Redirect then Page2.aspx would be shown.
So depending on what you want to optimise Response.Redirect are better if you want to support bookmarking of pages correctly and Server.Transfers are better if you want to minimise client round trips to the server.
Oh, and do check out http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=15 it describes this much better with the caveats.
Upvotes: 12
Reputation: 1
Server.Transfer gives you an options to set parameter values to the destination page.
Upvotes: -2
Reputation: 61703
Server.Transfer()
only works with pages from your site, it means that the server starts rendering a new page from scratch.
Response.Redirect()
is a normal redirection, which works with any URL.
Upvotes: 2