Both “response.redirect” and “server.transfer” helps to navigate from one page to other page.
In “Server.Transfer” following is the sequence of how navigation happens:-
- User sends a request to navigate to other page.
- Server creates the page object, executes the complete page life cycle and creates the HTML output.
- The outputHTML response is then sent back to the client browser.
Now let’s says we want to navigate between pages which reside on different servers. Now in this scenario the server cannot create object of that page as the page is located on some other server. On that external server this server has no control. So for external navigation we need to use “Response.Redirect”.
In “Response.Redirect” following is the sequence of events for navigation:-
- Client sends a request to the server tonavigate to some other page.
- Server sends the request back to the client browser telling him to do it as that page is not located in his server.
- Client then sends a HTTP “get” request to the other server for the page and that server creates the page object and sends the response back to the client browser.
Note: – It is possible to use “Response.Redirect” to navigate pages from the same server but then unnecessarily we are making extra round trip to achieve the same.
Uses of “Server.Transfer” and “Response.Redirect”
Use “Server.Transfer” when you want to navigate pages which resides on the same server , use ‘Response.Redirect’ when you want to navigate between pages which resides on different server.
Also click and see the following ASP.NET interview questions video on Response.Redirect (False VS True).