blog

Home / DeveloperSection / Blogs / Response.Redirect() and Server.Transfer()

Response.Redirect() and Server.Transfer()

Anchal Kesharwani9139 14-Aug-2014

In this blog, I’m explaining the concept of Response.Redirect() and Server.Transfer() method.

Response.Redirect() and Server.Transfer() both methods are user for user page transfer on page to another page. Both methods are same like as but some but some differences. Response.Redirect() sends an HTTP request to the browser, then the browser sends that request to the web server, then the web server delivers a response to the web browser.

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 webserver 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 webserver then after 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

Response.Redirect() Syntax as like:

Response.Redirect()("webForm2.aspx");

Server.Transfer() Syntax as like:

Server.Transfer()("webForm2.aspx");

Difference between Response.Redirect() and Server.Treansfer()

·     Response.Redirect() can be used for both .aspx and HTML pages whereas Server.Transfer() can be used only for .aspx pages and is specific to ASP and ASP.NET.

·    Response.Redirect() can be used to redirect a user to an external website. Server.Transfer() can be used only on sites running on the same server. You cannot use Server.Transfer() to redirect the user to a page running on a different server.

·    When you use Server.Transfer(), then the previous page also exists in server memory while in the Response.Redirect() method, the previous page is removed from server memory and loads a new page in memory.

Example
Step 1

Create a form as given below:

Step 2

Write code in the webForm1.aspx file

using System;
publicpartialclasswebForm1 : System.Web.UI.Page
{
    string MethodName;
    protectedvoid btnResponseRedirect_Click(object sender, EventArgs e)
    {
       
        Response.Redirect()("view.aspx");
    }
    protectedvoid btnServerTransfer_Click(object sender, EventArgs e)
    {
        Server.Transfer()("view.aspx");
    }
}

Step 3

Run the application click on Redirect From Response button.

Step 4

Click on Redirect From Server button.


Updated 18-Sep-2014

Leave Comment

Comments

Liked By