tags:

views:

115

answers:

4

will any one please elaborate this

+1  A: 

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.

Bastien Léonard
+7  A: 

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.

David McEwing
awesome answer!The way I see it,Server.Transfer handles the request on the server sideResponse.Redirect makes another round trip from the client
PieterG
Actually, `Response.Redirect` issues a "302 Moved Temporarily". 304 is "Not modified", which tells the browser to use its cached version, otherwise spot on. As a point of interest, ASP.NET 4 introduces `Response.RedirectPermanent` which issues a "301 Moved Permanently".
Zhaph - Ben Duguid
@Zhaph, good info on the .RedirectPermanent. Doing a 301 isn't all that many lines of code, but a shortcut is still nice.
Anthony Pegram
A: 

Server.Transfer gives you an options to set parameter values to the destination page.