ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  Managing ASP.NET Navigation
Subject:   Clarifications on when to use Response.Redirect vs. Response.Execute/Transfer
Date:   2003-04-14 14:57:23
From:   prosser
In most cases use of Response.Redirect or Response.Transfer boils down to whether you have control of the destination page and whether the user should "know" about the transfer. Performance, although differing between the methods, is not usually the key concern for me when I make this decision.


For example, when I worked for a certain large website, we would often get links from partner sites, and link out to partner sites. Since there was money involved in tracking those clicks, there had to be a tracking mechanism or "funnel" to make that sort of thing feasible. On incoming hits we could use Response.Transfer (we didn't--more on that later), since we controlled the destination page. On outgoing clicks we had to use Response.Redirect (there's no place to transfer to, so you must HTTP/1.0 302 redirect the request).


Even if you control the destination page, another consideration is the URL that shows up on the user's address bar. If you use Response.Transfer/Execute, the pre-transfer URL will appear in their address bar; Response.Redirect will result in the post-transfer URL appearing in their address bar. Now you may not really care that much, but in some cases you definitely should. For example, if you pay for click-throughs from a partner, do you REALLY want to pay them every time a user hits refresh on that page? How about when a user bookmarks the page? Even though there is a (small) performance gain for a single use of Response.Transfer it is balanced against the fact that if a user bookmarks the destination URL, they are actually bookmarking the pre-transfer URL, and so your server must keep transfering them every time ad infinitum (perhaps earning money for a partner each time as well).


That having been said, there's definitely a place for Server.Transfer. I use it after form validations in a "wizard" scenario, since you want to defeat bookmarks there anyhow and to keep the business logic where it makes sense--on the page that hosts the form the user just filled out. Call me silly but I don't care for pages where I have to validate a post from a previous page... the disconnect bothers me.


Just my $0.02,


Peter