Ranganathan's Blog

Techie

Sunday, July 25, 2004

Server.Transfer VS Response.Redirect

Server.Transfer is often a better choice than Response.Redirect.

Example: Let's say you're on A.aspx and you want to send the user to B.aspx.

Response.Redirect flowA.aspx calls Response.Redirect("B.aspx",false); which sends a 302 redirect header down to the client browser, telling it that the asset it has requested (A.aspx) has moved to B.aspx, and the web application terminates. The client browser then sends a request to the webserver for B.aspx. IIS tells asp_wp.exe to process the request. asp_wp.exe (after checking authentication and doing all the other setup stuff it needs to do when a new request comes in) instantiates the appropriate class for B.aspx, processes the request, sends the result to the browser, and shuts down.

Server.Transfer flowA.aspx calls Server.Transfer("B.aspx");. ASP.NET instantiates the appropriate class for B.aspx, processes the request, sends the result to the browser, and shuts down.

Note that Server.Transfer cuts the load on the client and the server. Server.Transfer is easier to code for, too, since you maintain your state. Information can be passed through the HTTP Context object between the pages, eliminating the need to pass information in the querystring or reload it from the database.

More info http://dotnetjunkies.com/WebLog/familjones/archive/2004/04/08/11020.aspx and http://www.eggheadcafe.com/articles/20030531.asp.

0 Comments:

Post a Comment

<< Home