Faster Page Redirections
We normally use Response.Redirect in our ASP scripts to redirect the user from one page to another. But Response.Redirect normally sends a 302 Redirect Request to the client browser which then initiates a next HTTP Request to the server with the correct URL that the webserver might have put in the HttpHeader in the Location value. Though this gives a nice way to jump between the URLs, the catch is that it incurs a (costly) roundtrip between the HttpServer and the client browser. The simple and directly visible costs that might be visible are:
- Slow Browsing Speed for the Client User Surfing at your Website
- Extra Bandwidth Usage for the WebServer to serve that request.
Starting from IIS 5, ASP engine (version 3.0) provides an elegant way for this type of redirects, with a method in Server Object called Server.Transfer. Server.Transfer redirects requests to the page in the serverside itself, without additional 302 location headers to the client browser.
There is one another catch with Response.Redirect. On a very slow connection, sometimes, when the user hits the Browser Stop button, it just says
Object Moved
It may be found here
where here is hyperlinked to the URL that was contained in the 302 Redirect status line.
ASP Sample (with Response.Redirect)
Copy paste the code below into a blank new ASP page from Visual InterDev and run it from your webserver.
Note: It would be very fast from localhost and hence you might not be able to see the differences. Try out from a remote webserver instead. You need to have a blank page called remotepage.asp, in the same folder as the ASP script to which you are saving the following code snippet for the following snippets to work.
<%
Response.Redirect ("remotepage.asp");
%>
ASP Sample (with Server.Transfer)
<%
Server.Transfer ("remotepage.asp");
%>
Some Highlights
There are certain changes in
Server.Transfer and
Response.Redirect compared to its Classic ASP counterparts. The following may be noted.
Server.Transfer has an overload now, which indicates whether to preserve the form data as the processing is transferred to the new page.
Response.Redirect has an overload now, which indicates whether to stop execution of the current page.
NOTE:
One note however is yet to be mentioned. Since webfarms are a common feature nowadays and webfarms consist of multiple webservers serving webrequests for a particular domain, and because of my little experience and exposure to Web Farms, that area is likely to be researched and to be determined whether Server.Transfer would really help in that area too. But for that for a website/web application in ASP, hosted from a straight single webserver, this article, I hope, would surely guide you towards a most fast ASP code.
Summarizing:
Though it is just a syntax feature, highlighting a difference between Response.Redirect and Server.Transfer, it has more advantages that a costly roundtrip and waiting time for the web surfer visiting the web application is avoided. This provides a interactive browsing experience for the web user. Additionally, it may also provide some bandwidth cost savings, since most of the webhosts, who charge for the amount of data transferred through their pipes.