Forums » .NET » ASP.NET »

Difference Between Response.Redirect and Server.Transfer


Posted Date: 27 Jan 2006      Posted By:: Qaiser Mehmood Mughal Profile photo    Member Level: Bronze  Member Rank: 0     Points: 2   Responses: 6

What is Difference Between Response.Redirect and Server.Transfer

Responses

#39947    Author: Sujit Kumar      Member Level: Gold      Member Rank: 0     Date: 27/Jan/2006   Rating: 2 out of 52 out of 5     Points: 2

Redirect and Transfer both cause a new page to be processed. But the interaction between the client (web browser) and server (ASP.NET) is different in each situation.

Redirect: A redirect is just a suggestion – it's like saying to the client “Hey, you might want to look at this". All you tell the client is the new URL to look at, and if they comply, they do a second request for the new URL.

If you want to pass state from the source page to the new page, you have to pass it either on the URL (such as a database key, or message string), or you can store it in the Session object (caveat: there may be more than one browser window, and they'll all use the same session object).

Transfer: A transfer happens without the client knowing – it's the equivalent of a client requesting one page, but being given another. As far as the client knows, they are still visiting the original URL.

Sharing state between pages is much easier using Server.Transfer – you can put values into the Context.Items dictionary, which is similar to Session and Application, except that it lasts only for the current request. (search for HttpContext in MSDN). The page receiving postback can process data, store values in the Context, and then Transfer to a page that uses the values.

Regards,
Sujit Kumar


 
#64780    Author: Rahul R. Gaykar      Member Level: Silver      Member Rank: 0     Date: 26/Jul/2006   Rating: 2 out of 52 out of 5     Points: 2

Server.Transfer() : client is shown as it is on the requesting page only, but the all the content is of the requested page. Data can be persist accros the pages using Context.Item collection, which is one of the best way to transfer data from one page to another keeping the page state alive.
Server.Transfer does not update the clients url history list or current url.
ex :- server.transfer("webform1.aspx")


Response.Dedirect() :client know the physical loation (page name and query string as well). Context.Items loses the persisitance when nevigate to destination page.
ex :- response.redirect("webform1.aspx")


In earlier versions of IIS, if we wanted to send a user to a new Web page, the only option we had was Response.Redirect. While this method does accomplish our goal, it has several important drawbacks. The biggest problem is that this method causes each page to be treated as a separate transaction. Besides making it difficult to maintain your transactional integrity, Response.Redirect introduces some additional headaches. First, it prevents good encapsulation of code. Second, you lose access to all of the properties in the Request object. Sure, there are workarounds, but they're difficult. Finally, Response.Redirect necessitates a round trip to the client, which, on high-volume sites, causes scalability problems. As you might suspect, Server.Transfer fixes all of these problems. It does this by performing the transfer on the server without requiring a roundtrip to the client.

transferring to another page using Server.Transfer conserves server resources. Instead of telling the browser to redirect, it simply changes the "focus" on the Web server and transfers the request. This means you don't get quite as many HTTP requests coming through, which therefore eases the pressure on your Web server and makes your applications run faster.

But watch out: because the "transfer" process can work on only those sites running on the server, you can't use Server.Transfer to send the user to an external site. Only Response.Redirect can do that.
Secondly, Server.Transfer maintains the original URL in the browser. This can really help streamline data entry techniques, although it may make for confusion when debugging.


 
#66699    Author: Stella Evangelin.J      Member Level: Gold      Member Rank: 0     Date: 03/Aug/2006   Rating: 2 out of 52 out of 5     Points: 2

http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=15




 
#281184    Author: asdf      Member Level: Silver      Member Rank: 0     Date: 14/Aug/2008   Rating: 2 out of 52 out of 5     Points: 0

Server.Transfer don't have round trip back to client browser. So client url's still remines the existing the url.
Response.Redirect have round trip. So client Url(uniform resource locator) will be change.


 
#283933    Author: RobinHood      Member Level: Gold      Member Rank: 0     Date: 20/Aug/2008   Rating: 2 out of 52 out of 5     Points: 6

Response.Redirect..
If the requested page is in new location, this informs the browser.Then the browser initiates another request to the new page loading its contents in the browser. This results in two requests by the browser.

Server.Transfer..
The execution is transfered from one page to another page on the server.The browser client is made one request and the initial page is the one responding with content.Also, any posted form variables and query string parameters are available to the second page as well.

For more ideas, Verify these links..
http://www.geekinterview.com/question_details/15806
http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=15
http://www.dotnetuncle.com/Difference/82_servertransfer_responseredirect.aspx

Regards
Sridhar R
Nothing is illegal, Until You Get Caught


 
#295035    Author: Bunty      Member Level: Gold      Member Rank: 0     Date: 13/Sep/2008   Rating: 2 out of 52 out of 5     Points: 6

Hi,

The difference between Server.Transfer and Response.Redirect are as follow

1>Response.redirect sends message to the browser saying it to move to some different page while Server.transfer does not send any message to the browser but rather redirects the uyser directly from the server itself.So in Server.transfer their is no round trip while Response.redirect has a round trip hence puts a load on the server.

2>Using Sever.transfer you cannot redirect to a different server itself while using Response.redirect you can redirect to a different server also.

3>With Server.transfer you can preserve your information.It has a parameter called as "preserve form",so the existing query string etc will be avilable in the calling page.This is not possible in Response.redirect.

Regards
S.S.Bajoria


Thanks & Regards


Bunty


 
Post Reply     

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.





  • Return to Discussion Forum
  • Start new thread


  • Top Contributors
    Today
      Last 7 Daysmore...

      Awards & Gifts
       
      Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India