none
difference between Server.Transfer and Response.ReDirect

    Question

  •  

     

    hi all,

    I am almost new in asp.net.

    I am trying to understand the difference between Server.Transfer and Response.Redirect.

     

    I have got so many differences between  these two mwthods.

    Such as--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.

     

     

    But i want to know the  difference incase of Round Trip.I can not understand it properly.

    It is written that Response.Redirect needs a extra round trip..but how???

     

    Suppose,i have two pages.

     

    Default1.aspx with a button control

    and

    Default2.aspx

     

    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??

     

    is the server finds the Default.aspx page from the server and send it to the Browser.

     

    But for Server.Transfer,same thing happens or something else??

     

    Can anybody plz tell me elaborately the difference??Can anybody give a code snippet so that i can visualise what exactly happening under the hood??

     

    I have another 1 question.

     

    What roundtrip exactly means?????

     

    Is it from server to the server or client to the client?????

    There is a lots of confusion in it.

     

    It will be very very helpfull for me.

    Plz somebody help me.

    Thanx in advace.
    Tuesday, June 19, 2007 11:22 AM

Answers

  • 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.

    Hope this helps Smile
    Tuesday, June 19, 2007 12:15 PM
  • Server.Transfer also transfer the .Form data to the next page
    Tuesday, June 19, 2007 4:53 PM
  • Yes exactly. In addition to that. The form data will not be forwarded on the Response.Redirect & Server.Transfer will do.

     

    Wednesday, June 20, 2007 9:30 AM

All replies

  • 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.

    Hope this helps Smile
    Tuesday, June 19, 2007 12:15 PM
  • Server.Transfer also transfer the .Form data to the next page
    Tuesday, June 19, 2007 4:53 PM
  •  

     

    hii,

     

     

    ya i have got the points.

     

     

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

     

    If my understanding is ok then plz  send me a notification reply

     

    Many many thankx in advance

    Wednesday, June 20, 2007 7:17 AM
  • Yes exactly. In addition to that. The form data will not be forwarded on the Response.Redirect & Server.Transfer will do.

     

    Wednesday, June 20, 2007 9:30 AM
  • hii,

    thanx everybody who helped me to clear the conception.

    Wednesday, June 20, 2007 12:23 PM
  • Thank you all for active participation and sharing your valuable experience with us here!

     I have marked your replies as answers.

     

     Hi JustALearner

     If you got your answer, please remember to mark it as answer in future. If not, please let us know what else you need.
       Thank you for your support!Smile

    Thursday, June 21, 2007 7:51 AM
  • Hi guys, have a look of the following article also for this question.
    http://techahead.wordpress.com/2007/10/14/aspnet-servertransfer-vs-responseredirect/
    Wednesday, December 12, 2007 4:27 PM
  • Following are the major differences between them:- 1 Response.Redirect sends message to the browser saying it to move to some different page, while server.transfer does not send any message to the browser but rather redirects the user directly from the server itself. So in server.transfer there is no round trip while response.redirect has a round trip and hence puts a load on server. 2 Using Server.Transfer you can not redirect to a different from the server itself. Example if your server is www.yahoo.com you can use server.transfer to move to www.microsoft.com but yes you can move to www.yahoo.com/travels, i.e. within websites. This cross server redirect is possible only using Response.redirect. 3 With server.transfer you can preserve your information. It has a parameter called as “preserveForm”. So the existing query string etc. will be able in the calling page. In response.redirect you can maintain the state, but has lot of drawbacks.
    Wednesday, April 06, 2011 5:38 AM