Tuesday, November 3, 2009

Response.Redirect and Server.Transfer

Response.Redirect:

Response is the object which accumulates the HTML/Javascript for the page requested. Each response has an associated Request object. Request object has the information about HTTP request headers and request body. Request body contains posted parameters.



I've used Web Developer helper tool to show you the details of HTTP Request & Response. HTTP request is comprised of HTTP command(e.g. GET,POST HEAD etc.) alongwith HTTP Headers (e.g. User-Agent) and the request body,if any. Request body appears only if user is posting some selections / values back to HTTP server. Diagram (1) shows you the details of HTTP Request.


The image below shows the GET Request body.



The images below show the POST request with Request body





If Response.Redirect is used to change the page to be shown, there is no access method available to access the posted values on second page. The reason : Response.Redirect involves round-trip to redirect the browser to new page. Browser redirection to new page has new request. Request body of first request of the round-trip lost unprocessed.



Response.Redirect helps to redirect to different server. Page on test.com can be redirected to google.com.



In essence, Response.Redirect involves one round-trip with two different requests. Response.Redirect loose the first-request body. Use Response.Redirect to redirect the browser to some page of different server. For same server, my suggestion is to use hyperlink or Server.Transfer.


Server.Transfer:

Server object represents the server processing request. Server.Transfer cannot transfer to the page of different server. Server.Transfer does not involve any round-trip. Request body is available to new page (of same server)as no round-trip involves.

Post a Comment