Analysis of the difference between Response.Redirect and Server.Transfer in asp.net

  • 2020-05-10 17:59:29
  • OfStack

The Server.Transfer method moves the execution process from the current ASPX file to another ASPX page on the same server. When Server.Transfer is called, the current ASPX page terminates execution and the execution process moves to another ASPX page, but the new ASPX page still USES the reply flow created by the previous 1ASPX page.
If you use the Server.Transfer method to navigate between pages, the URL in the browser will not change, because the redirection is completely on the server side and the browser has no idea that the server has performed a page transformation.
Response.Redirect is the first time the client requests the server to return the status code 302 and the new URL, the client requests the new URL again, and the server returns the new page, which is one more response than Server.Transfer.


1. Generally speaking, if you need to share data between two pages, and the data volume is relatively large, transfer is more suitable. In the second page, you can directly use the data from the first page.

eg:
TransferToPage.aspx
 
if(Context.Handler is TransferFromPage) 
{ 
TransferFromPage post=(TransferFromPage)Context.Handler; 
startWeekID=Int32.Parse(post.DdlStartWeek.SelectedValue); 
endWeekID=Int32.Parse(post.DdlEndWeek.SelectedValue); 
} 

Directly reference the value of the previous 1 page control.
Redirect can pass some smaller string values.
Response.Redirect( "b.aspx?id=0&name=Jeff ");

Related articles: