Friday, September 26, 2008

Difference between Response.Redirect and Server.Transfer

Server.Transfer can not be used to go to a page of a different website whereas Response.Redirect can do.

Response.Redirect can be used for both .html and .aspx pages but Server.Transfer works only for aspx pages

Explanation :

If i have two different pages Default1.aspx and Default2.aspx
and In the button click event of the Default1.aspx i wrote a code
Response.Redirect("Default2.aspx");
Now when i click the button ,the page will posted to the server and the code will be executed there.
Then what happens??

Response.Redirect sends message to browser saying that the browser should request some other page so basically it means that:

1. Browser is on page default1.aspx on which there is a Response.Redirect("") command which means that the server sends response (message) to browser that browser should request some other page default2.aspx
2. Browser sends request to server in order to get this page default2.aspx
3. Server sends page default2.aspx to browser


Server.Transfer doesn't tell the browser to request page default2.aspx. It just sends page default2.aspx, so e.g., browser address bar still shows the original page's URL.

Roundtrip is the combination of a request being sent to the server and response being sent back to browser.

Request is the message that the browser sends to the server and Response is the message the server sends back to the browser.

Server.Transfer also transfer the .Form data to the next page

Response.Redirect there are two round trips and in case of server.transfer there are only one roundtrip.

No comments: