Response.Redirect and Server.Transfer are objects of ASP.NET. These two objects serves the same functions but carry out their operations in different ways.
When any of these two objects is used, a redirection will occur meaning the client will be transferred from one web page to another.
To learn about other means of page redirection, check
this post
Server.Transfer is used to navigate to other pages or sites running on the same web server.
Syntax:
Server.Transfer(path)
Where path refers to the location of the file to which control should be transfered
The Response.Redirect() method is used to redirect a user from one page to another and also letting the user know that you have been redirected from your current page to another.
It has the following syntax;
Response.Redirect(path)
Where path refers to the destination file that is requested by the client.
If you could noticed, both are used for navigating from one web page to another. However, there are noticeable differences between these two techniques:
- Response.Redirect() do not reduce server request hence do not conserve server resources. While Server.Transfer() reduces the server request and conserves server resources.
-
Response.Redirect() can be used to redirect the users to another web-page on the same server or external server. While Server.Transfer can also be used to redirect users to another web page but only on the same server.
- Response.Redirect always change the address bar from the current page to the destination page. While Server.Transfer keeps the address of the current web page and still transfer user to the destination page.
- When Response.Redirect() is used, form variables are are not transferred. While Server.Transfer() method has a second parameter known as preserveForm. If this is set to True, the existing query string and form variables will be available to the transferred page.
Server.Transfer(“mypage2.aspx”, True)