Click here to Skip to main content
13,042,819 members (63,497 online)
Click here to Skip to main content
Add your own
alternative version


25 bookmarked
Posted 11 Feb 2014

Difference Between Response.Redirect() and Server.Transfer() Methods in ASP.NET

Rate this:
Please Sign up or sign in to vote.
Here you will learn the difference between Response.Redirect() and Server.Transfer() Methods in ASP.NET


Both Response.Redirect and Server.Transfer methods are used to transfer a user from one web page to another web page. Both methods are used for the same purpose, but still there are some differences as follows.

The Response.Redirect method redirects a request to a new URL and specifies the new URL while the Server.Transfer method for the current request, terminates execution of the current page and starts execution of a new page using the specified URL path of the page.

Both Response.Redirect and Server.Transfer have the same syntax like:


HTTP Status Codes

Before touching on more points, I want to explain some HTTP status codes, these are important for the understanding of the basic differences between these two. The HTTP status codes are the codes that the Web server uses to communicate with the Web browser or user agent.

  1. HTTP 200 OK

    This is the most common HTTP status message. It indicates that the request was successful and the server was able to deliver on the request. The information returned with the response is dependent on the method used in the request. In a GET request, the response will contain an entity corresponding to the requested resource. In a POST request, the response will contain an entity describing or containing the result of the action.

  2. HTTP 302 Found

    The HTTP response status code 302 Found is a common way of performing a redirection. The 302 status code indicates that the resource you are requesting has redirected to another resource.

Response.Redirect and Server.Transfer Request Handling

Response.Redirect sends an HTTP request to the browser, then the browser sends that request to the web server, then the web server delivers a response to the web browser. For example, suppose you are on the web page "UserRegister.aspx" page and it has a button that redirects you to the "UserDetail.aspx" web page.

HTTP request to the browser

Figure 1.1 Request and Response using Response.Redirect method

You can notice in Figure 1.1 that when you run the application, then you get a web page successfully so the HTTP status code is "HTTP 200 OK". Then you click on the button that redirects to another page using the Response.Redirect method. The Response.Redirect method first sends a request to the web browser so it is the "HTTP 302 Found" status, then the browser sends a request to the server and the server delivers a response so it is "HTTP 200 OK". It is called a round trip. Let's see that in Figure 1.2.

Round Trip by Response.Redirect method

Figure 1.2 Round Trip by Response.Redirect method.

Server.Transfer sends a request directly to the web server and the web server delivers the response to the browser.

Request and Response using Server.Transfer method

Figure 1.3 Request and Response using Server.Transfer method

Now Figure 1.3 explains that the first request goes to the web server and then gets a response so the round-trip is not made by the Server.Transfer method. You get the same page response but different content. That means your web page URL in the address bar will not be changed. For example, see Figure 1.3 showing you get the same page as the previous request page so the previous page still remains while in Response.Redirect, you get a different page in the response (see Figure 1.1 ). That means the address bar URL will be changed in the Response.Redirect method and also updates the browser history so you can move back from the browser back button.

Server.Transfer method request and response

Figure 1.4 Server.Transfer method request and response

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.

Response.Redirect can be used to redirect a user to an external website. 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.

Using the Code

When you use Server.Transfer, then the previous page also exists in server memory while in the Response.Redirect method, the previous page is removed from server memory and loads a new page in memory. Let's see an example.

We add some items in the context of the first page "UserRegister.aspx" and thereafter the user transfers to another page "UserDetail.aspx" using Server.Transfer on a button click. The user will then be able to request data that was in the context because the previous page also exists in memory. Let's see the code.

Code of the UserRegister.aspx.cs page:

using System;
public partial class UserRegister : System.Web.UI.Page
    protected void btn_Detail_Click(object sender, EventArgs e)
        Context.Items.Add("Name", "Sandeep Singh Shekhawat");
        Context.Items.Add("Email", "");

Code of the UserDetail.aspx.cs page:

 using System;
public partial class UserDetail : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
            Response.Write(string.Format("My name is {0} and email address is {1}",
        catch (NullReferenceException ex)

Using the code above, we can get data from the previous page to the new page by the Context.Item collection. But if you use the Response.Redirect method, then you can't get context data on another page and get an exception object as null because the previous page doesn't exist in server memory.

Null Exception by Context object

Figure 1.5 Null Exception by Context object

Mostly the Server.Transfer method is preferable to use because Server.Transfer is faster since there is one less roundtrip, but some people say that Server.Transfer is not recommended since the operations typically flow through several different pages causing a loss of the correct URL of the page, but again it all depends on your requirement.

It is not a complete list. I wrote the basic differences between these two. If you know more differences, then please provide them in the comments.


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


About the Author

Sandeep Singh Shekhawat
Software Developer
India India
He is awarded for Microsoft TechNet Guru, CodeProject MVP and C# Corner MVP.

You may also be interested in...


Comments and Discussions

GeneralGreat article Pin
Member 1043365631-Jul-16 20:30
memberMember 1043365631-Jul-16 20:30 
GeneralNice description Pin
Er. Vikas Sangal26-Oct-15 19:30
memberEr. Vikas Sangal26-Oct-15 19:30 
QuestionUnexpected behaviour ... Pin
Member 1065156510-Aug-15 1:08
memberMember 1065156510-Aug-15 1:08 
QuestionSmall question Pin
Member 1051507413-Aug-14 0:01
memberMember 1051507413-Aug-14 0:01 
AnswerRe: Small question Pin
Sandeep Singh Shekhawat13-Aug-14 0:06
professionalSandeep Singh Shekhawat13-Aug-14 0:06 
GeneralRe: Small question Pin
NK Sharma13-Aug-14 1:37
memberNK Sharma13-Aug-14 1:37 
GeneralRe: Small question Pin
Sandeep Singh Shekhawat13-Aug-14 2:35
professionalSandeep Singh Shekhawat13-Aug-14 2:35 
GeneralRe: Small question Pin
NK Sharma13-Aug-14 2:42
memberNK Sharma13-Aug-14 2:42 
GeneralMy vote of 5 Pin
BSRK19-Jun-14 20:58
memberBSRK19-Jun-14 20:58 
GeneralRe: My vote of 5 Pin
Sandeep Singh Shekhawat2-Jul-14 18:17
professionalSandeep Singh Shekhawat2-Jul-14 18:17 
QuestionFor You Pin
Member 1059078417-Apr-14 0:15
memberMember 1059078417-Apr-14 0:15 
AnswerRe: For You Pin
Sandeep Singh Shekhawat17-Apr-14 0:27
professionalSandeep Singh Shekhawat17-Apr-14 0:27 
GeneralMy vote of 3 Pin
Xavi Giqwa11-Feb-14 21:56
memberXavi Giqwa11-Feb-14 21:56 
GeneralRe: My vote of 3 Pin
Sandeep Singh Shekhawat11-Feb-14 21:58
professionalSandeep Singh Shekhawat11-Feb-14 21:58 
Questionnice explanation Pin
blachsmith11-Feb-14 21:45
memberblachsmith11-Feb-14 21:45 
AnswerRe: nice explanation Pin
Sandeep Singh Shekhawat11-Feb-14 21:54
professionalSandeep Singh Shekhawat11-Feb-14 21:54 
GeneralRe: nice explanation Pin
blachsmith14-Feb-14 17:01
memberblachsmith14-Feb-14 17:01 
GeneralRe: nice explanation Pin
Sandeep Singh Shekhawat14-Feb-14 17:24
professionalSandeep Singh Shekhawat14-Feb-14 17:24 
GeneralMy vote of 5 Pin
@AmitGajjar11-Feb-14 17:45
professional@AmitGajjar11-Feb-14 17:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 11 Feb 2014
Article Copyright 2014 by Sandeep Singh Shekhawat
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid