Difference between Response.Redirect and Server.Transfer

Difference between Response.Redirect and Server.Transfer

01 Jun 2024
Intermediate
190K Views
5 min read

Difference between Response.Redirect and Server.Transfer: An Overview

In ASP.Net Technology both "Server" and "Response" are objects of ASP.Net. Server.Transfer and Response.Redirect both are used to transfer a user from one page to another. But there is some remarkable differences between both the objects which are as follow. In this Tutorial, we will try to understand What is Response.Redirect?, What is Server.Transfer? and Difference between Response.Redirect and Server.Transfer. Consider enrolling in ASP.NET Certification Training for deeper understanding.

Read More: Top 50 ASP.NET Core Interview Questions and Answers for 2024

Difference between Response.Redirect and Server.Transfer

Response.Redirect and Server.Transfer, both are used to transfer the users from one page to another, but in different ways. Let's have a look at their differences through this comparison table:

FeatureResponse.RedirectServer.Transfer
PurposeWith Response.Redirect, the user is redirected to a new page.

With Server.Transfer, the execution is transferred to a new page on the same server.

Round TripsIt usually require two requests, that is, one to the original page and one to the redirected page.It only requires a single request to the server.
URL ChangeThe URL in the user's browser changes.The URL remains the same.
PerformanceAn additional round trip makes it slower.

It is comparatively faster.

User awarenessThe user is completely aware that they are being redirected to another page.The user is unaware of the transfer as the URL in the browser does not change.

Difference between Response.Redirect and Server.Transfer

Read More: How can you become an ASP.NET developer

Response.Redirect

  1. Response.Redirect() will send you to a new page, update the address bar and add it to the Browser History. On your browser you can click back.

  2. It redirects the request to some plain HTML pages on our server or to some other web server.

  3. It causes additional roundtrips to the server on each request.

  4. It doesn’t preserve Query String and Form Variables from the original request.

  5. It enables to see the new redirected URL where it is redirected in the browser (and be able to bookmark it if it’s necessary).

  6. Response. Redirect simply sends a message down to the (HTTP 302) browser.

Server.Transfer

  1. Server.Transfer() does not change the address bar, we cannot hit back.One should use Server.Transfer() when he/she doesn’t want the user to see where he is going. Sometime on a "loading" type page.

  2. It transfers current page request to another .aspx page on the same server.

  3. It preserves server resources and avoids the unnecessary roundtrips to the server.

  4. It preserves Query String and Form Variables (optionally).

  5. It doesn’t show the real URL where it redirects the request in the users Web Browser.

  6. Server.Transfer happens without the browser knowing anything, the browser request a page, but the server returns the content of another.

When to use "Server.Transfer" and when to use "Response.Redirect" ?

Use Server.Transfer:

  1. When you want to transfer the user to another page on the same server and you don't want the user to know about the transfer.
  2. When you want to save the data between pages. Use Context.Items collection or PreviousPage property.
  3. When you want it be quicker as it does not require another round trip to the user.

Use Response.Redirect:

  1. When you want to redirect the user to a whole new page that has a different URL.
  2. When you want that the user is made of them being redirected to another page as the new URL will be visible in the address bar.
  3. When you want the redirection to pages on totally different domains.
Summary

In this article I have tried to explain the difference between Response.Redirect and Server.Transfer also I explain some scenario when and where we should use each one. I hope the article will be helpful for you. Learn more about core concepts of ASP.NET and how to use them in real-time through our comprehensive step-by-step course ASP.NET Certification.

FAQs

Q1. What is Response.Redirect() in ASP.Net?

Response.Redirect is a method in ASP.NET which is used to redirect the user to a completely different URL which can also be seen in the browser's address bar..

Q2. What is Server.Transfer() in ASP.Net?

Server.Transfer() in ASP.NET is a method which is used to transfer the user from one page to another on the same server without the user being aware of the transfer.

Q3. What is the difference between server transfer & response redirect?

The main difference between Server.Transfer and Response.Redirect is that Server.Transfer() will transfer the user to another page on the server without changing the URL while Response.Redirect redirects the user to a different URL.

Q4. What is the use of response redirect?

The Response.Redirect method is commonly used when you want to your users to navigate and transfer to different pages within a web application.

Q5. What is the best redirect method?

The choice of best redirect method depends on your requirements:
  1. If you want a server-side navigation without revealing the new URL, use Server.Transfer method.
  2. If you want to redirect the user and it's okay for the URL change to be seen, use Response.Redirect method.
Share Article
About Author
Shailendra Chauhan (Microsoft MVP, Founder & CEO at Scholarhat by DotNetTricks)

Shailendra Chauhan is the Founder and CEO at ScholarHat by DotNetTricks which is a brand when it comes to e-Learning. He provides training and consultation over an array of technologies like Cloud, .NET, Angular, React, Node, Microservices, Containers and Mobile Apps development. He has been awarded Microsoft MVP 8th time in a row (2016-2023). He has changed many lives with his writings and unique training programs. He has a number of most sought-after books to his name which has helped job aspirants in cracking tough interviews with ease.
Accept cookies & close this