locked
Server.transfer vs Reponse.redirect RRS feed

  • Question

  • User527076549 posted

    Both Response.Redirect and Server.transfer used to navigate to different page. To navigate to page on different server only Response.Redirect works.

    Server.transfer is useful to navigate between pages which are in same server.

    Then why people prefer Response.Redirect over Server.Transfer to navigate between pages in same server ?

    Monday, October 15, 2018 11:07 AM

Answers

  • User475983607 posted

    Then why people prefer Response.Redirect over Server.Transfer to navigate between pages in same server ?

    A redirect is an HTTP 302 response returned to the browser that tells the browser to do an HTTP GET to another URL; location header.  The browser makes the request, the server returns the requested resource and the new URL is shown in the browser's address bar.

    https://msdn.microsoft.com/en-us/library/540y83hx.aspx

    A server transfer passes execution from the requested page to the transferred page on the server.  The target page can see all the members from the original request.   The results shown in the browser come from the transferred page while the URL in the browser's address bar shows the originally requested page. 

    https://msdn.microsoft.com/en-us/library/ms525800%28v=vs.90%29.aspx?f=255&MSPPError=-2147217396

    There's lots of blog examples on the internet that show the differences and explain scenarios when to use one over the other.

    http://computerauthor.blogspot.com/2014/05/#%E2%80%9CServer.Transfer%E2%80%9Dvs%E2%80%9Cresponse.Redirect%E2%80%9D

    IMHO, the reason redirect is used more often than transfer is because the designer wants the URL to change to reflect the content on the page. This is important because relative references are based on the URL in the address bar.

    I recommend building a test project to compare Redirect and Transfer which should help with your understanding.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 15, 2018 11:29 AM
  • User-821857111 posted

    They are, as mgebhard said, completely different things. So it's not a question of preferring one over the other to achieve the same objective. The problems that Server.Transfer are designed to solve were never really that common, and are much rarer these days when URL rewriting is pretty simple to implement. Response.Redirect on the other hand has always been an important component in implementing the Post-Redirect-Get pattern:

    https://en.wikipedia.org/wiki/Post/Redirect/Get

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 15, 2018 2:14 PM

All replies

  • User1120430333 posted

    https://www.codeproject.com/Articles/775221/Server-Transfer-VS-Response-Redirect-Simplified

    The books and tutorials teach Response.Redirect, and it's monkey see monkey do, right?

    Monday, October 15, 2018 11:26 AM
  • User475983607 posted

    Then why people prefer Response.Redirect over Server.Transfer to navigate between pages in same server ?

    A redirect is an HTTP 302 response returned to the browser that tells the browser to do an HTTP GET to another URL; location header.  The browser makes the request, the server returns the requested resource and the new URL is shown in the browser's address bar.

    https://msdn.microsoft.com/en-us/library/540y83hx.aspx

    A server transfer passes execution from the requested page to the transferred page on the server.  The target page can see all the members from the original request.   The results shown in the browser come from the transferred page while the URL in the browser's address bar shows the originally requested page. 

    https://msdn.microsoft.com/en-us/library/ms525800%28v=vs.90%29.aspx?f=255&MSPPError=-2147217396

    There's lots of blog examples on the internet that show the differences and explain scenarios when to use one over the other.

    http://computerauthor.blogspot.com/2014/05/#%E2%80%9CServer.Transfer%E2%80%9Dvs%E2%80%9Cresponse.Redirect%E2%80%9D

    IMHO, the reason redirect is used more often than transfer is because the designer wants the URL to change to reflect the content on the page. This is important because relative references are based on the URL in the address bar.

    I recommend building a test project to compare Redirect and Transfer which should help with your understanding.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 15, 2018 11:29 AM
  • User-821857111 posted

    They are, as mgebhard said, completely different things. So it's not a question of preferring one over the other to achieve the same objective. The problems that Server.Transfer are designed to solve were never really that common, and are much rarer these days when URL rewriting is pretty simple to implement. Response.Redirect on the other hand has always been an important component in implementing the Post-Redirect-Get pattern:

    https://en.wikipedia.org/wiki/Post/Redirect/Get

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 15, 2018 2:14 PM