Recently I had to respond to an issue which was a result of using wrongly of the aforementioned in web forms. Each of them are used with a specific purpose and not as an alternative to another. And so let see when to use either of them and in what situations.
They do have distinct notable differences. One of them being with Response.Redirect the browser url changes to the targeted page while in Server.Transfer the url remains the same.
With Response.Redirect a HTTP 302 message is usually sent do the browser while in Server.Transfer all happens without the browser knowing anything, and it ends up recieving a different content from the requested.
Another difference is that the Server.Transfer consumes more server power in comparison to Response.Redirect.
Server.Transfer cant send a user to an external site while Response.Redirect can.
When to use Response.Redirect:
- we want to redirect the request to some plain HTML pages on our server or to some other web server
- we don’t care about causing additional roundtrips to the server on each request
- we do not need to preserve Query String and Form Variables from the original request
- we want our users to be able to see the new redirected URL where he is redirected in his browser (and be able to bookmark it if its necessary)
When to use Server.Transfer:
- we want to transfer current page request to another .aspx page on the same server
- we want to preserve server resources and avoid the unnecessary roundtrips to the server
- we want to preserve Query String and Form Variables (optionally)
- we don’t need to show the real URL where we redirected the request in the users Web Browser
I do hope this will help someone out there who needs to find which to use and when. This might not be exhaustive but it’s worthy you consideration