Thursday, July 12, 2012

Response.Redirect vs Server.Transfer

Server.Transfer does a server side transfer.

Response.Redirect does a client side redirect - the server informs thebrowser to redirect.
So here's the flow:


Server.Transfer
1. Client Request Page HelloWorld.ASPX2. Server.Transfer -> Server send a different page to the client3. Client Receives Page still thinking it's HelloWorld.ASPX.4. Client's URL (Address bar) remains HelloWorld.ASPX since the page wassent on the server side and the client doesn't know a different page wassent.


Response.Redirect
1. Client Requests Page HelloWorld.ASPX2. Response.Redirect -> Server sends a HTTP header informing that theuser should redirect. 3. Client sees the redirect notice and requestsAnotherPage.ASPX 4. Server sends AnotherPage.ASPX5. Client's URL (address bar) shows AnotherPage.ASPX
Technically speaking, Server.Trasfer is faster since there 1 lessroundtrip, but you lose the URL of the page. Server.Transfer also allowsfor more flexibilty since you can use HTTPContext.Items to passvariables beteen pages

No comments:

Post a Comment