Signup/Sign In

Difference between Response.Redirect() and Server.Transfer() in ASP.Net

Posted in Programming   AUGUST 17, 2022

    Both "Server" and "Response" are objects of ASP.Net. Both Response.Redirect and Server.Transfer are used for the same purpose of transferring a user from one web page to another web page. Despite the similarity, there are some differences between these two objects.

    Let's understand both Response.Redirect and Server.Transfer and know the differences between the two of these.

    Difference between Response.Redirect and Server.Transfer

    Syntax

    Both methods have the same syntax as follows:

    Response.Redirect("NewPage.aspx");
    Server.Transfer("NewPage.aspx");

    Difference Between Response.Redirect and Server.Transfer

    1). Response.Redirect

    • Response.Redirect redirects the page request to the HTML pages on our server or it can send it to another web server too.
    • It updates the address bar when it redirects to a new page and you can click back also.
    • Query string and Form Variables are not preserved from the original request.
    • You can bookmark the redirected page.
    • It allows you to see the new redirected URL in the Web Browser.
    • It just sends a message HTTP 302 to the browser.
    • Repsonse.Redirect causes additional roundtrips to the server on each request.

    2). Server.Transfer

    • Server.Transfer redirects the web page request to another .aspx page on the same server.
    • Unlike Response.Redirect, it does not update the address bar so you can't click back.
    • It optionally preserves the Quesry String and Form Variables.
    • You cannot bookmark the new redirected web page.
    • It doesn't show the redirected URL in the browser.
    • The Web Browser doesn't get to know anything when Server.Transfer happens. The server returns the content of another page when the browser requests a page.
    • Server.Transfer doesn't cause roundtrips and preserves server resources of the server.

    I hope this article helped you understand the difference between these two methods of ASP.Net. I tried to explain both of these Response.Redirect and Server.Transfer.

    Published by: avdhoottt
    Tags:ASP.Net
    IF YOU LIKE IT, THEN SHARE IT
     

    RELATED POSTS