Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Page Redirection Approaches in ASP.NET

Author: Mike Green

ASP.NET provides few ways to redirect to different pages in a web application. I will explain these techniques in this article.

In web applications, redirecting users to another page is a common aspect so we certainly need to move users from one page to another for different purposes. This redirection may be with user interaction or it can be for your own reason to accomplish something and redirect user to another page without user interaction. User interaction may be a click of a button or link or it may be selecting a value in a drop down list.

One technique for page redirection in ASP.NET, is Cross Page PostBack. You can read my detail article on it. I will briefly discuss other two techniques of page redirection in this article. These approaches are called Response.Redirect method and Server.Transfer method.

Response.Redirect

Response.Redirect is said to be a client side redirection. This technique is implemented by using client browser that means it is handled within the client's browser. When we use this method, by default, it halts the execution of the current page and redirect the user to another URL mentioned in the method. ASP.NET performs redirection in this method by sending 302 response to client's browser. The original request and the redirected request will make two requests to the server. When we use the overloaded version of the method with endResponse Boolean parameter set to false, it will continue execution of the current page at the same time redirecting to another page.

 

Response.Redirect("http://www.devasp.net")
Response.Redirect("http://www.devasp.net"False)

 

 

Server.Transfer

Server.Transfer is said to be a server side redirection. This technique is implemented in the web server that means this method performs redirection by avoiding HTTP requests. When we use this method, the state information for all the built-in objects are included in the transfer. This means that the values assigned in session or application scope to any variables or objects, are maintained. this method sends only one request to the server and eliminates one request instead of sending two requests in case of Response.Redirect.  In this method, since the server does not inform the change to the client's browser and the URL does not change in the browser so it can be a little confusing for users.

 

Server.Transfer("/default.aspx")

 

 

Pros and Cons

There are some advantages and disadvantages for both methods and the usage of each method depends on the situation and on your requirements.

Performance of the Server.Transfer method is better than Response.Redirect since Response.Redirect sends two calls to the server as oppose to the Server.Transfer which sends only one.

Server.Transfer method does not interact with the browser so it may possible that it breaks some JavaScript or AJAX functionality.

As I discussed it earlier,  Server.Transfer may cause some confusion in user's mind as URL displayed in the browser will not change.

The advantage of Server.Transfer method over Response.Redirect is that Server.Transfer provides some kind of security as we are not showing our data to the user but in case of Response.Redirect we are exposing our data to the user.

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to handle browser close event and abandon session in ASP.NET

Disclaimer - Privacy
© 2002-2017 DevASP.net