Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP .NET
Hi
 
what is the difference between Response.Redirect and server.Transfer?
 
If any one knows please let me know.
 
Thanks
M.Dhanasekaran
Posted 8-Apr-11 0:43am
Comments
Sandeep Mewara at 8-Apr-11 6:48am
   
Google?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Searched on google you can get answers to all your small questions :
 

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.
 

 
Response.Dedirect() :client know the physical loation (page name and query string as well). Context.Items loses the persisitance when nevigate to destination page. 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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Server.Transfer v/s Response.Redirect
 
Both “Server” and “Response” are objects of ASP.NET. Server.Transfer and Response.Redirect both are used to transfer a user from one page to another page. Both are used for the same purpose but still there are some differences are there between both that are as follows:
 
Syntactically both are different, if you want to transfer the user to a page named newpage.aspx then syntax for both methods will be,
 
Response.Redirect(“newpage.aspx”) and Server.Transfer(“newpage.aspx”)
Response.Redirect involves a roundtrip to the server whereas Server.Transfer conserves server resources by avoiding the roundtrip. It just changes the focus of the webserver to a different page and transfers the page processing to a different page.
 
Roundtrip means in case of Response.Redirect it first sends the request for the new page to the browser then browser sends the request for the new page to the webserver then after your page changes But in case of Server.Transfer it directly communicate with the server to change the page hence it saves a roundtrip in the whole process.
 
If you are using Server.Transfer then you can directly access the values, controls and properties of the previous page which you can’t do with Response.Redirect.
 
Suppose you are currently on the Page1.aspx and now you are transferring the user to the Page2.aspx using Response.Redirect then When the Page2 page is requested, Page1 has been flushed from the server’s memory and no information can be retrieved about it unless the developer explicitly saved the information using some technique like session, cookie, application, cache etc. But in case of Server.Transfer variables can stay in scope and Page2 can read properties directly from Page1 because it’s still in memory, as you know the Server.Transfer just changes the focus from page1 to page2 So in this case browser doesn’t know that any change is happen there that’s why with this method you can access the information about the previous page.
 
Response.Redirect changes the URL in the browser’s address bar. So they can be bookmarked. Whereas Server.Transfer retains the original URL in the browser’s address bar. It just replaces the contents of the previous page with the new one.
 
Actually in case of Server.Transfer it directly contact with the webserver for the new page request, it doesn’t involve the browser, so that browser doesn’t know that there is any change happen. But in case of Response.Redirect as you know it first send the request (for new page) to the browser then further processing will be performed, so here browser knows that yes there is some change in the browser window that’s why it changes the URL in the address bar.
So, the matter “No change of address in the browser address bar” This is a good thing if you see it from security point of view but it creates problem in case if you refresh your page or in case you want to add bookmark of that page. In case of refresh and bookmark it will add perform both the action with the URL currently present in the address bar, but as you know Server.Transfer doesn’t changes the URL, so sometimes it creates problem.
 
Response.Redirect can be used for both .aspx and html pages whereas Server.Transfer can be used only for .aspx pages and is specific to ASP and ASP.NET.
 
With Response.Redirect you can redirect the user to the both type of pages .html or .aspx like below,
Response.Redirect(“mypage.html”) OR Response.Redirect(“OtherPage.aspx”)
But in case of Server.Transfer you can only work with .asp or .aspx page like below
Server.Transfer(“mypage.asp”) OR Server.Transfer(“OtherPage.aspx”)
 
Response.Redirect can be used to redirect a user to an external websites. Server.Transfer can be used only on sites running on the same server. You cannot use Server.Transfer to redirect the user to a page running on a different server.
 
Suppose on some action on the webpage I want to redirect my user to the http://www.yahoo.com so with Response.Redirect you can redirect your user to the external site, but in case of Server.Transfer you can only work with the .asp or .aspx pages that are present in your site.
 
Now the question is which to use and when to use? Mostly the Server.Transfer method is preferable to use because Server.Transfer is faster since there is one less roundtrip, but in some people say that Server.Transfer is not recommended since the operations typically flow through several different pages due to which you lose the correct URL of the page, but again all depends on your requirement.
Server.Transfer also allows for more flexibility since you can use HTTPContext.Items to pass variables between pages so, use Server.Transfer when you need to pass context items. Otherwise use Response.Redirect so the user will always see the correct URL in the address bar.
 
I mentioned the most common differences here if anyone knows any other difference other than these then please give your comments.
 
Thank you,
 
Jigar Malik
  Permalink  
v3
Comments
bhoopendrasharma at 22-Jun-12 2:23am
   
"With Response.Redirect you can redirect the user to the both type of pages .html or .aspx like below,
Response.Redirect(“mypage.html”) OR Response.Redirect(“OtherPage.aspx”)
But in case of Server.Transfer you can only work with .asp or .aspx page like below
Server.Transfer(“mypage.asp”) OR Server.Transfer(“OtherPage.aspx”)
"
As per your above solution, we found that html page can not be used in server.transfer,but we are able to used html page in server.transfer.
Kindly give me your input for the same.
deepu kumar at 3-Oct-12 14:16pm
   
nice answer......................
ateeq@tekskills at 12-Dec-12 1:47am
   
Solution 3 and 4 was Awsome......! its very much understandable for fresher's....!
Thanks bro
Member 10994431 at 14-Aug-14 5:21am
   
best answer
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Respose.redirect
---------------------------------------------------
Respose.redirect can use another appliaction url.
It has round trip.
Its much slower than server.transfer.
 
Server.transfer
---------------------------------------------------
In server.transfer we can use with in that application only.
It has not round trip.
it has faster than response.redirect
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

11 main Difference between Response.Redirect and Server.Transfer in asp.net
http://www.webcodeexpert.com/2013/03/difference-between-responseredirect-and.html
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 8

Response.Redirect should be used when:
 
we want to redirect the request to some plain HTML pages on our server or to some other web server
 
we don't care about causing additional roundtrips to the server on each request
 
we do not need to preserve Query String and Form Variables from the original request
 
we want our users to be able to see the new redirected URL where he is redirected in his browser (and be able to bookmark it if its necessary)
 
Server.Transfer should be used when:
 
we want to transfer current page request to another .aspx page on the same server
 
we want to preserve server resources and avoid the unnecessary roundtrips to the server
 
we want to preserve Query String and Form Variables (optionally)
 
we don't need to show the real URL where we redirected the request in the users Web Browser
 
check it is helpful or not..
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 10

The below codeproject article should help out.
Server.Transfer VS Response.Redirect – Simplified[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 19 May 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100