8.1.10

Server.Transfer Vs Response.Redirect

* Response.Redirect
-It involves a roundtrip to the server.
-you cannot directly access the values, controls and properties of the previous page.
-Suppose you are currently on the Page1.aspx and now you are transferring the user to the Page2.aspx using Response.Redirect then When the Page2 page is requested, Page1 has been flushed from the server’s memory and no information can be retrieved about it unless the developer explicitly saved the information using some technique like session, cookie, application, cache etc
-Response.Redirect can be used for both .aspx and html pages
-Response.Redirect can be used to redirect a user to an external websites.
* Server.Transfer
-It conserves/Preserves server resources by avoiding the roundtrip.
-you can directly access the values, controls and properties of the previous page which you can’t do with Response.Redirect.
-variables can stay in scope and Page2 can read properties directly from Page1 because it’s still in memory, as you know the Server.Transfer just changes the focus from page1 to page2 So in this case browser doesn’t know that any change is happen there that’s why with this method you can access the information about the previous page.
-Server.Transfer can be used only for .aspx pages and is specific to ASP and ASP.NET.
-Server.Transfer can be used only on sites running on the same server. You cannot use Server.Transfer to redirect the user to a page running on a different server.
- you can put values into the Context.Items dictionary for using these values in next page.
eg.
Context.Items["Message"] = "Your password was changed successfully";
Server.Transfer("default.aspx");