Results 1 to 2 of 2

Thread: Redirect to a Page

  1. #1

    Redirect to a Page

    What's the difference between Server.transfer() and Response.Redirect() methods


  2. #2
    Moderator
    Join Date
    Dec 2010
    Answers
    40

    Re: Redirect to a Page

    Response.Redirect involves a roundtrip back to the client.

    Here's what it is:
    1) You type-in the url in the browser, http://www.somedomain.com/Page1.aspx. Your browser would translate it to a HTTP GET request for Page1.aspx on somedomain.com

    2) The request reaches the somedomain server (through TCP/IP somehow) and the server starts processing Page1.aspx.

    While processing Page1.aspx it comes across Response.Redirect("Page2.aspx"). This redirection then gets translated into a HTTP Response "302 - Object Moved" which is sent back to the client.

    3) The client/browser receives the response as HTTP 302 and knows that it has to submit another HTTP GET request for Page2.aspx. The address bar of the browser changes to http://www.somedomain.com/Page2.aspx and a new HTTP GET request is sent to the server for Page2.aspx on somedomain.com

    HTML Code:
    Internet Explorer > HTTP GET Page1 > Page 1 > Response.Redirect("Page2") > Internet Explorer > request Page2 > Page 2 > Internet Explorer
    The 2nd request for Page2.aspx is like a new request initiated from the browser. Since, the url changes on the browser the user gets to know that there has been a change on the page it initially requested.

    Server.Transfer does not involve a roundtrip to the server. The transfer of control from Page1.aspx to Page2.aspx happens on the server itself and the end user doesn't come to know about it.

    Using the same example,
    1) You type-in the url in the browser, http://www.somedomain.com/Page1.aspx. Your browser would translate it to a HTTP GET request for Page1.aspx on somedomain.com

    2) The request reaches the somedomain server (through TCP/IP somehow) and the server starts processing Page1.aspx.

    While processing Page1.aspx it comes across Server.Transfer("Page2.aspx"). The server would process Page2.aspx now and renders whatever comes out of it back to the client/browser.

    3) The brower sees the rendered html, which actually is from Page2.aspx but the user is unknown about the change. The browser would still be showing http://www.somedomain.com/Page1.aspx on the address bar.

    HTML Code:
    Internet Explorer > HTTP GET Page1 > Page 1 > Server.Transfer("Page2") > Page 2 > Internet Explorer

    With Server.Transfer, the whole HTTP context is still available on Page2.aspx coz the transfer of control is within the server itself and no new request is initiated for it from the browser.

    HTH!!!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact