Server.Transfer vs. Response.Redirect - Jon Galloway

Server.Transfer vs. Response.Redirect

Server.Transfer is often a better choice than Response.Redirect.

Example:Let's say you're on A.aspx and you want to send the user to B.aspx.

Response.Redirect flow
A.aspx calls Response.Redirect("B.aspx",false); which sends a 302 redirect header down to the client browser, telling it that the asset it has requested (A.aspx) has moved to B.aspx, and the web application terminates. The client browser then sends a request to the webserver for B.aspx. IIS tells asp_wp.exe to process the request. asp_wp.exe (after checking authentication and doing all the other setup stuff it needs to do when a new request comes in) instantiates the appropriate class for B.aspx, processes the request, sends the result to the browser, and shuts down.

Server.Transfer flow
A.aspx calls Server.Transfer("B.aspx");. ASP.NET instantiates the appropriate class for B.aspx, processes the request, sends the result to the browser, and shuts down.

Note that Server.Transfer cuts the load on the client and the server.

Server.Transfer is easier to code for, too, since you maintain your state. Information can be passed through the HTTP Context object between the pages, eliminating the need to pass information in the querystring or reload it from the database.

More info here and here.

Published Wednesday, July 21, 2004 12:29 AM by Jon Galloway
Filed under:

Comments

# re: Server.Transfer vs. Response.Redirect

Jon I totally agree. The only problem with Server.transfer is that you don't see the in the browser th URL of the page called. Just make addresses less cleaner.
But yes definitly a winner to pass variables using a context.

Wednesday, July 21, 2004 4:52 AM by Paschal

# re: Server.Transfer vs. Response.Redirect

Server.Transfer also bypasses any authentication on the page you transfer to. See my blog post here:
http://dotnetjunkies.com/WebLog/darrell.norton/archive/2003/08/26/1270.aspx

Wednesday, July 21, 2004 9:41 AM by Darrell

# Server.Transfer o Response.Redirect, para enviar a los usuarios a otra pagina?

Ninguno , si sólo deseamos pasar un usuario a otro página y no vamos a cambiar el destino dinámicamente...

Saturday, September 30, 2006 6:02 PM by Sergio Tarrillo's Blog -> enhancements

# Server.Transfer o Response.Redirect, para enviar a los usuarios a otra pagina?

Ninguno , si sólo deseamos pasar un usuario a otro página y no vamos a cambiar el destino dinámicamente

Saturday, September 30, 2006 6:02 PM by SergioTarrillo's Blog

# re: Server.Transfer vs. Response.Redirect

Hey dudes, I totally agreee that we can have to use Server.Transfer

but definietly i would say for smaller applications it is better to use Response.Redirect as

1.There won't an overhead of refresh.

2.Use the Singleton conclet on Datasets and classes to achieve the Mismatch of data.

3.Change of browser address..

Monday, March 05, 2007 12:43 AM by Pratap.BVNP

# re: Server.Transfer vs. Response.Redirect

@Pratap.BVNP:

1. Not sure I follow you. Both Response.Redirect and Server.Transer will require a page refresh. Response.Redirect will generally cause the client browser to take longer to refresh, since it will require an extra round trip from server to client.

2. I'm sorry, I don't understand what you're saying there. When we're talking about moving data between pages, though, keep in mind that ASP.NET 2.0's cross page posting can simplify a lot of these scenarios.

3. Change of browser address. Absolutely, I agree with you there.

Monday, March 05, 2007 1:21 AM by Jon Galloway

# re: Server.Transfer vs. Response.Redirect

I usually use Response.Redirect but some times i had problems with redirections to the same page. Example. I have on top a form to attach images and at bottom the actual collection of attached images. If remove a item of collection with ServerVb code and finally run a Response.Redirect("same page"), this dont work fine.

NOTE. this collection is loaded form BBDD all times at Page Load.

Think Server.Transfer would run better?

Thx

Thursday, July 12, 2007 5:24 PM by Adolfo García

# re: Server.Transfer vs. Response.Redirect

Its fine

I want to see diagram form. What is happening between server and client servertransfer and response.redirect

Tuesday, September 11, 2007 3:18 AM by Narasimha

# re: Server.Transfer vs. Response.Redirect

The "server.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.

Wednesday, December 12, 2007 6:10 AM by KiranReddy

# re: Server.Transfer vs. Response.Redirect

Hi Jon,

for this particular question, take alook of the following url,

techahead.wordpress.com/.../aspnet-servertransfer-vs-responseredirect

Wednesday, December 12, 2007 11:23 AM by Prashant Pandey

# re: Server.Transfer vs. Response.Redirect

How do you know what page you're on with Server.Transfer?  My pages are totally table driven, so I need to know what page I'm actually on.  I use Me.Request.Url.AbsolutePath to determine the page name and make my request from the database.  If I were to switch to Server.Transfer, then how would I do this?

Saturday, February 16, 2008 8:32 PM by Larry

# re: Server.Transfer vs. Response.Redirect

I am using two sitemaps and I determine in the master.cs which one to use due to user login role. Server.Transfer seemed to break this. Response.Redirect does not.

Thursday, March 06, 2008 9:48 PM by Shawn

# re: Server.Transfer vs. Response.Redirect

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.

Response.Redirect can be used for both .aspx and html pages whereas Server.Transfer can be used only for .aspx pages.

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.

Response.Redirect changes the url in the browser. So they can be bookmarked. Whereas Server.Transfer retains the original url in the browser. It just replaces the contents of the previous page with the new one.

Sunday, March 30, 2008 10:41 AM by dorai

# re: Server.Transfer vs. Response.Redirect

I have a problem , when i use server.transfer to transfer to another page ,then i use request.form to get a value of a previous page's control it returns null but it works fine in IE just problem with FF.

Can anyone help me out of this ?

Many thanks.

Monday, June 02, 2008 5:04 AM by anhvu

# re: Server.Transfer vs. Response.Redirect

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.

Friday, June 06, 2008 7:05 AM by Indresh

# re: Server.Transfer vs. Response.Redirect

Important

Server.Transfer can pass variables with HTTPContext.Items

AND

access to PreviousPage is possible

Peter

Thursday, September 04, 2008 6:29 AM by Peter

# re: Server.Transfer vs. Response.Redirect

Good Day. A synonym is a word you use when you can't spell the word you first thought of. Help me! Could you help me find sites on the: Flonase manufacturer. I found only this - <a href="genericflonase.info/.../">generic for flonase nasal spray</a>. Flonase, bountiful accommodations in new york city are not discoverable to decrease in this most large exam of the acne. Flonase, exercise is one of the games most few songwriters. With best wishes :-), Makale from Eritrea.

Thursday, March 25, 2010 9:29 AM by Makale

# Void AbortInternal() - Difference between Server.Transfer &#038; Response.Redirect - System.Threading.ThreadAbortException | Take Away Notes

Pingback from  Void AbortInternal() - Difference between Server.Transfer &#038; Response.Redirect - System.Threading.ThreadAbortException | Take Away Notes

# re: Server.Transfer vs. Response.Redirect

nice information

Sunday, December 12, 2010 2:51 AM by ali_raza159

# re: Server.Transfer vs. Response.Redirect

Friday, June 03, 2011 8:21 AM by niranjan444

# re: Server.Transfer vs. Response.Redirect

Its really to good to see this article get more about this here www.vishalpatwardhan.com/.../difference-between-servertransfers-and.html

Monday, February 06, 2012 2:18 AM by vishal patwardhan

Leave a Comment

(required) 
(required) 
(optional)
(required)