Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Difference between server. transfer and response.redirect
Posted
Comments
CodeHawkz 19-Sep-12 4:49am    
Why don't you guys use Google? :S
Server.Transfer vs Response.Redirect[^]
Volynsky Alex 16-May-13 3:37am    
Response.Redirect sends HTTP code 302 down to the users browser along with the new URL location of the wanted page.
HTTP Code 302 actually means ' The requested resource resides temporarily under a different URI'.After browser receives this code it tries to open the new location of the resource that was suggested by the server.This actually causes two requests to the server, first one to the original URL, and second to the new URL that is suggested via 302 response.All the Query Strings and Form variables are lost during the redirect and they are not available to the redirected URL.

Also its important to say that the new URL can reside on the same server but also it can be on some other server and the redirected URL does not need to be .aspx page it can be regular HTML page also).So we can us the Redirect method to redirect users request to another page on our server like this:
Response.Redirect("newPage.html");
or to redirect our it to some other server like this:
Response.Redirect("http://www.someotherserver.com/newPage.aspx");

In contrast to all this when we call Server.Transfer we do not initiate another request to the server, but the original request is simply rewritten and transfered to some other page on the same server.
(This off course means that we can use it only to transfer requests to the pages on the same server, not to some other servers and we can only transfer to .aspx pages and not other page types like HTML, php etc).

All posted Form variables and query strings can optionally remain available to the second Page where we transfered request (if we use second overload Server.Transfer(string path, bool preserveForm) and supply true for the second parameter).
Otherwise the Form Variables and Query String are cleared just like when we use Redirect.
WARNING: If you use this method to preserve Query String and Form variables and receive error: "View State Is Invalid" its because your EnableViewStateMac attribute of the <pages> element is set to true. More on this error on this page: PRB: "View State Is Invalid" Error Message When You Use Server.Transfer

Its also important to note that because of the way Server.Transfer works, after the transfer, the URL shown in the users Web Browser remains the original one that was requested, because browser has no knowledge that its request was transfered (transfer occurs on the server side).

TIP: One thing to be careful about when using the Server.Transfer is to clear the the HttpResponse object with Response.Clear method on the transfered page to avoid any output from the first page to be shown on the second page.

So now that we know what are the similarities and differences between these two approaches we can try to use them wisely.

For more information, please see following post:
http://www.aspdotnetfaq.com/Faq/what-is-the-difference-between-server-transfer-and-response-redirect-methods.aspx

hey,
have yo searched it on Google?

see the below link on Cp:
what is the difference between Response.Redirect and server.Transfer?[^]
 
Share this answer
 
It is quite easy to find the difference in Google[^]. You could have tried that.

Server.Transfer()[^]: The Transfer method sends all of the information that has been assembled for processing by one .asp file to a second .asp file.
Response.Redirect()[^]: Any response body content such as displayed HTML text or Response.Write text in the page indicated by the original URL is ignored. In addition, code execution in the current page is terminated when the Redirect method is processed, so subsequent code in the page will also be ignored.

Simple Difference:
Server.Transfer acts as an efficient replacement for the Response.Redirect method. Response.Redirect specifies to the browser to request a different page. Because a redirect forces a new page request, the browser makes two requests to the Web server, so the Web server handles an extra request. IIS 5.0 introduced a new function, Server.Transfer, which transfers execution to a different ASP page on the server. This avoids the extra request, resulting in better overall system performance, as well as a better user experience.


--Amit
 
Share this answer
 
Comments
Sharon 2 14-Dec-12 1:56am    
main difference between server.transfer and response.redirect?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900