Server Transfer vs. Response Redirect

Difference Between Server Transfer and Response Redirect

Server and Response are two different objects in ASP.NET. Server object is responsible for providing properties and procedures for different tasks associated with server. Information of the current state is sent to another .asp file by transfer method of server object for processing. Response object describes properties and procedure associated with server’s response. It uses .Redirect method for connecting a browser to URL.

Both these methods, Transfer and .Redirect can transfer users to another pages but they do it different ways.

Response method sends the url of the web page requested by the user and HTTP code 302 to the browser used by the user. This code lets the browser know that the requested resource is at a different URL. After receiving the code the browser opens the resource in the new URL location. The requested web page can remain on the same or a different server.

Now, if the web page resides on the server on which the current page is residing then the response method will be

Response.Redirect(“nextPage.html”)

If the web page resides on another server the response method will be:

Response.Redirect(“nextPage.html”);

After this let us know about Server. Transfer method. When this method is called, the original request is changed for transferring it to other pages on the same server. The URL that is seen in the web browser of the user does not change if the new page is requested by using Server.Transfer. The reason behind this is that this transfer takes place in the server side without letting the browser know anything about it. We use the second overload and set second parameter as true for server. transfer (string path, bool preserveForm). With this we can make the query strings and posted form variables available to the second page.

Here are some differences between the two:

  • Both have Syntactical difference.
  • Server.Transfer works by shifting the focus of web server to another web page while Response.Redirect works by making a round trip to the server. You can preserve the resources by using Server.Transfer.
  • Server.Transfer can be used for redirecting the users to web pages on different server while Server.Transfer can do this on the same server only.
  • Server.Transfer allows you to access previous page’s properties but this is not possible in case of Response.Redirect.

Server.Transfer allows you to retain the original URL and still replace the contents of the web page. This is why you cannot bookmark it. In case of Response.Redirect the URL is changed every time you access a new page.

 

Category: VS  |  Tags: