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.


  • 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.

  • 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..

  • @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.

  • 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?

  • Its fine

    I want to see diagram form. What is happening between server and client servertransfer and 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?

  • 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.

  • 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.

  • 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.

  • Important
    Server.Transfer can pass variables with HTTPContext.Items
    access to PreviousPage is possible


  • You can also read here

Comments have been disabled for this content.