Difference Between Server.Transfer and Response.Redirect

Server and Response both are objects in ASP.NET. Server object provides methods and properties for various tasks related to a server. Transfer is a method of the Server object and it sends information of the current state to another .asp file for processing. Response object describes methods and properties related to a server’s response. Redirect is a method of the Response object and it sends a message to the browser making it connect to a different URL. Even though both the Server.Transfer and Response.Redirect can be used to transfer a user from one page to another, they are different in how they actually perform this task.

What is Response.Redirect?

Redirect is a method in the Response object. When the Response method is called, it sends the HTTP code 302 and the URL of the requested web page to the users’ browser. The HTTP code 302 informs the users’ browser that the requested resource is located under a different URL. When the browser receives the code, it opens the resource in the new location. The requested web page can reside on the same server as the page that contained the request or it could be residing in some other server. When requesting a web page residing on the same server as the current page, Response method can be used as follows:

Response.Redirect(“nextPage.html”);

When requesting a web page residing on another server, Response method can be used as follows:

Response.Redirect(“http://www.newServer.com/newPage.aspx”);

What is Server.Transfer?

As mentioned earlier, Transfer is a method of the Server Object. When the Transfer method is called, the original request is modified to transfer in to some other page in the same server. When a new page is requested using the Server.Transfer, URL shown in the users’ web browser does not change. This is because the transfer happens in the server side and the browser does not have any knowledge about the transfer. By using the second overload for Server.Transfer(string path, bool preserveForm) and setting the second parameter as true, posted form variables and query strings can be made available to the second page.

What is the difference between Server.Transfer and Response.Redirect?

Even though both the Server.Transfer and Response.Redirect can be used to transfer a user from one page to another, there are some differences between the two methods. Besides the apparent syntactical difference, Response.Redirect makes a roundtrip to the server, while Server.Transfer changes the focus of the web server to a different web page. Therefore, by using Server.Transfer, server resources can be preserved. On the other hand Response.Redirect could be used to redirect the user to a web page in another server whereas Server.Transfer can only be used to redirect the user to web pages on the same server. Also by using Server.Transfer, properties of the previous page can be accessed by the new page but this is not possible with Response.Redirect. Additionally, Response.Redirect changes the URL in the address bar of the browser when the new page is accessed but when using the Server.Transfer the original URL is retained and the content of the page is just replaced. So the user cannot use it to bookmark the new page.