Skip to main content

Difference between Response.Redirect and Server.Transfer in asp.net?


Response.Redirect vs Server.Transfer
1. ‘Response. Redirect’ sends message to the browser saying it to move to some different page, while ‘Server. Transfer’ does not send any message to the browser but rather it redirects the user directly from the server itself. So in case of ‘Server. Transfer’ there is no round trip while Response. Redirect has a round trip and hence puts extra load on server.
2. Using ‘Server. Transfer’ we cannot redirect to external websites or website pages. E.g. if your website is www.kunalsaurav.com then you cannot use ‘Server. Transfer’ to move to www.google.com but yes, you can move to internal pages www.kunalsaurav.com/asp.net, i.e. within the websites. Cross server redirection is possible only by using ‘Response.Redirect’ i.e. it allows redirection to internal as well as external websites and website pages.
3. With ‘Response. Redirect’ we can redirect the user to the both type of pages .html or .aspx e.g. Response. Redirect (“OtherPage.html”) OR Response. Redirect (“OtherPage.aspx”) But in case of ‘Server. Transfer’ we can redirect user to .asp or .aspx pages only e.g. Server. Transfer (“OtherPage.asp”) OR Server. Transfer (“OtherPage.aspx”) not to Server. Transfer (“OtherPage.html”).
4. In ‘Server. Transfer’ URL doesn’t change but in case of ‘Response. Redirect’ URL changes.
5. When we want to allow our website’s URL can be copied then ‘Response. Redirect’ is better but for security reasons ‘Server. Transfer’ is better because URL cannot be copied.
6. ‘Response. Redirect’ has a round trip but ‘Server.Transfer’ has no round trip. (Roundtrip is the combination of a request being sent to the server and response being sent back to browser.)
7. ‘Server. Transfer’ is a server process whereas ‘Response. Redirect’ is a client process.
8. ‘Server.Transfer’ preserves Query String and Form Variables (optionally). ‘Response. Redirect’ doesn’t preserve Query String and Form Variables from the original request.
9. ‘Server. Transfer’ is faster since there is one less round trip as compared to ‘Response. Redirect’. Transferring to another page using ’Server. Transfer’ conserves server resources. Instead of telling the browser to redirect, it simply changes the focus on the Web server and transfers the request. This means you don't get quite as many HTTP requests coming through, which therefore eases the pressure on your Web server and makes your applications run faster.
10. ‘Server. Transfer’ allow us to directly access the values, controls and properties of the previous page which we can’t do with ‘Response. Redirect’. The ’Server. Transfer’ method also has a second parameter—"preserveForm". If you set this to True, using a statement such as Server. Transfer ("OtherPage.aspx", True), the existing query string and any form variables will still be available to the page you are transferring to. For example, if your CurrentPage.aspx has a TextBox control called TextBox1 and you transferred to OtherPage.aspx with the preserveForm parameter set to True, you'd be able to retrieve the value of the original page’s TextBox control by referencing Request. Form ("TextBox1").
11. ‘Response. Redirect’ involves a roundtrip to the server whereas ‘Server. Transfer’ conserves server resources by avoiding the roundtrip. It just changes the focus of the web server to a different page and transfers the page processing to a different page. Roundtrip means in case of ‘Response. Redirect’ it first sends the request for the new page to the browser then browser sends the request for the new page to the web server only then a your page changes But in case of ‘Server. Transfer’ it directly communicate with the server to change the page hence it saves a roundtrip in the whole process.

Comments

Popular posts from this blog

What is cookie? Advantages and disadvantages of cookies?

What is cookie? A cookie is a small piece of text file stored on user's computer in the form of name-value pair. Cookies are used by websites to keep track of visitors e.g. to keep user information like username etc. If any web application using cookies, Server send cookies and client browser will store it. The browser then returns the cookie to the server at the next time the page is requested. The most common example of using a cookie is to store User information, User preferences, Password Remember Option etc.It is also one of the common and mostly asked interview questions. Some facts about Cookie Here are a few facts to know about cookies: · Cookies are domain specific i.e. a domain cannot read or write to a cookie created by another domain. This is done by the browser for security purpose. · Cookies are browser specific. Each browser stores the cookies in a different location. The cookies are browser specific and so a cookie created in one browser(e.g in Google Chrome

Code First Getting Started

In this tutorial let us create a simple application to demonstrate the use of entity framework using code first. We are using Visual Studio 2015 and entity framework 6.1.3. You can download Visual Studio community Edition . You should have the basic knowledge of .Net framework, C# and MS SQL Server. In this tutorial, we will create a simple application with a user class.  Our user class will have basic information like name and email address of the user. Create the Project Open Visual Studio. File ->New -> Project Select C# -> Select Console Application Name the application as “EFGettingStarted” Click on OK Install Entity Framework The next step is to install the Entity framework. This can be installed via nuget package console. Click on Tools->Nuget Package manager -> Package Manager Console and type the following command C# 1 2 3   install - package entityframework   This will install the late

First, FirstOrDefault, Single, SingleOrDefault In C#

For people who are new to LINQ, it is difficult to understand the difference between First, FirstOrDefault, Single, SingleOrDefault. In this blog, I will explain what to use and when.     I will take a simple example to make you understand practically how these methods work.   Consider a class Employee with properties as Id, Name, and Department. class  Employee {    public   int  Id {  get ;  set ; }    public   string  Name {  get ;  set ; }    public   string  Department{  get ;  set ; } } I have a list of Employees: List<Employee> employeeList =  new  List<Employee>(){    new  Employee() { Id = 1, Name =  "Sunny" , Department =  "Technical"  },    new  Employee() { Id=2, Name= "Pinki" , Department = "HR" },    new  Employee() { Id=3, Name= "Tensy" , Department = "Finance" },    new  Employee() { Id=4, Name= "Bobby" , Department = "Technical" },    new