tags:

views:

2960

answers:

7

what is difference between Server.Transfer & Response.Redirect & what are advantages & disadvantages of one over another ?

+13  A: 

Response.Redirect simply sends a message down to the (HTTP 302) browser.

Server.Transfer happens without the browser knowing anything, the browser request a page, but the server returns the content of another.

CMS
And you even mention the HTTP Response Code. Awesome.
Dustman
+1  A: 

Response.Redirect is more costly since it adds an extra trip to the server to figure out where to go.

Server.Transfer is more efficient however it can be a little mis-leading to the user since the Url doesn't physically change.

In my experience, the difference in performance has not been significant enough to use the latter approach

deadbug
A: 

Transfer is entirely server-side. Client address bar stays constant. Some complexity about the transfer of context between requests. Flushing and restarting page handlers can be expensive so do your transfer early in the pipeline e.g. in an HttpModule during BeginRequest. Read the MSDN docs carefully, and test and understand the new values of HttpContext.Request - especially in Postback scenarios. We usually use Server.Transfer for error scenarios.

Redirect terminates the request with a 302 status and client-side roundtrip response with and internally eats an exception (minor server perf hit - depends how many you do a day) Client then navigates to new address. Browser address bar & history updates etc. Client pays the cost of an extra roundtrip - cost varies depending on latency. In our business we redirect a lot we wrote our own module to avoid the exception cost.

stephbu
+8  A: 

Response.Redirect will send you to a new page, update the address bar and add it to the Browser History. On your browser you can click back.

Server.Transfer does not change the address bar, you cannot hit back.

I'll use Server.Transfer when I don't want the user to see where I am going. sometimes on a "loading" type page.

Otherwise I'll always use Response.Redirect

Christian Payne
+1  A: 

The advantages and disadvantages have been stated within the site below. http://www.developer.com/net/asp/article.php/3299641

One interesting point in the article is that Server.Transfer consumes more server power in comparison to Server.Redirect.

codemeit
Note that this link is from 2004. Early 2004.
quillbreaker
+3  A: 

Response.Redirect requires another roundtrip, you ask the client to change page. Server.Transfer change that page without doing this roundtrip and because of this is less "costly".

So.. I try to use Server.Transfer whenever i can but sometimes for example when you need to set at cookie on the client you're required to use response.redirect.

+1  A: 

A good explanation, ASP.NET - Server.Transfer v/s Response.Redirect

Prashant
This link is dead
Christian Payne
@Christian, Updated the link, please check it again.
Prashant