Server.Transfer VS Response.Redirect
Server.Transfer and Response.Redirect both are used to transfer a user from one page to another. Both Response.Redirect and Server.Transfer has same syntax like:
Above two methods are used for the same purpose but still there are some differences as follows.
Response.Redirect() sends a redirection header to the client , and the client itself requests the new page while the Server.Transfer method for the current request, terminates execution of the current page and starts execution of a new page using the specified URL path of the page.
Response.Redirect should be used when:
- Redirect the request to some plain HTML pages on our server or to some other web server
- Don't care about causing additional roundtrips to the server on each request
- Do not need to preserve Query String and Form Variables from the original request
- Users to be able to see the new redirected URL where he is redirected in his browser
Server.Transfer should be used when:
- Transfer current page request to another .aspx page on the same server
- Preserve server resources and avoid the unnecessary roundtrips to the server
- Preserve Query String and Form Variables (optionally)
- Don't need to show the real URL where we redirected the request in the users Web Browser