What is the difference between server.transfer and response.redirect ?
Shivprasad
First of all these both are the methods from which you can redirect your pages.
Now coming to the differences which is given below:
1.Response.Redirect() requires the roundtrip to the server while Server.Transfer() doesnot require the roundtrip to the server.
Roundtrip means the page send the request to the browser and then the browser send the request to the webserver where as Server.Transfer() changes the focus of the webserver to another page so the resources are consumed less.
2.Response.Redirect() can't access the values,control and properties of the previous page whereas Server.Transfer() can access the previous page values,controls and properties.
3.Response.Redirect() can redirect a user to an external websites but Server.Transfer() cannot redirect the user to a page running on the different server.
4.Response.Redirect() can be used for the .html and .aspx page whereas Server.Transfer() can be used for the .aspx page only.
5.Response.Redirect() changes the URL in the browser's address bar so,they can be bookmarked whereas Server.Transfer() retains the original URL in the browser's address bar.
This is one of the favorite questions in ASP.NET Interviews. Every interviewer would like to know from the .NET candidate two things, how they differ technically and which scenarios should we use them.
Technical difference :- In Response.Redirect the following steps happen :-
1 - Client browser sends a signal to the server that he wants to go to xyz.aspx.2 - Server responds back to the browser about the location of xyz.aspx and tells the client to go to that
location.3- Client gets the response and redirects to xyz.aspx.
In server.transfer the the following step happens :- 1 - Client browser sends a signal to the server that he wants to go to xyz.aspx.2 - Server redirects to xyz.aspx and send the output to the client. In other words in response.redirect there is a round trip while in server.transfer there are no round trips.
The next question what interviewer will ask is so does that mean we should always use server.trasfer and response.redirect is never needed.
Both of the are useful under different scenarios. Response.redirect is good when we want to go cross domains , in other words you want to redirect from http://www.questpond.com/ to http://www.microsoft.com/. Server.trasfer do not work when you go cross domains.
22 top important .NET interview questions