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:


# 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

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 5, 2007 12:43 AM by Pratap.BVNP

# re: Server.Transfer vs. Response.Redirect


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 5, 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?


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

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 6, 2008 9:48 PM by Shawn

# 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 2, 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 6, 2008 7:05 AM by Indresh

# re: Server.Transfer vs. Response.Redirect


Server.Transfer can pass variables with HTTPContext.Items


access to PreviousPage is possible


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

# re: Server.Transfer vs. Response.Redirect

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