Response.Redirect and Server.Transfer Demystified
I still remember the old days when I first learned ASP.NET 1.0, I used to search, like other newcomers, for the differences between Response.Redirect and the Server.Transfer. I found answers such as Server.Transfer had been kept in ASP.NET for backward compatibility with ASP so the recommendation was to use Response.Redirect or that I should be using the Server.Transfer for better performance!
The truth is every method has a completely different and important use.
Response.Redirect : When you call this method, ASP.NET will issue HTTP headers that will instruct the browser for the new page tonavigate to and will stop processing any further ASP.NET instruction. The following code:
Response.Redirect("default2.aspx"); throw new Exception("This exception will not be executed!");
will redirect to default2.aspx and will not execute the next line. It will issue an HTTP header instruction to the browser as follows:
Then the browser will request the new page “default2.aspx”.
Server.Transfer : This method will transfer execution ON THE SERVER from the current executing page to the new page “default2.aspx” without notifying the client (the browser) of this change. Also, will stop executing any further instruction on the current page.
Server.Transfer("default2.aspx"); throw new Exception("This exception will not be executed!");