Powered by Blogger.

Saturday, March 1, 2014

Difference between Server.Transfer and Respose.Redirect in Asp.Net




In this post we will discuss about what is the difference between Server.Transfer and Respose.Redirect in Asp.Net.

Also you can check my previous articles o:

- Get all user defined tables in SQL Server 2008

- How to get body height using jQuery in Asp.Net?

- Write exception to Event Log in Asp.Net C#.Net

Respose.Redirect():
- HttpResponse.Redirect() method is used to send the user to another page.

- Example:
Response.Redirect("~/Page2.aspx");

- When you use the Redirect() method, ASP.NET immediately stops processing the page and
sends a redirect message back to the browser. Any code that occurs after the Redirect() call won’t be executed.

When the browser receives the redirect message, it sends a request for the new page.

- Redirect() method can send the user to any type of page.

- Even you can send to other web sites like below:

Response.Redirect("http://www.aspdotnethelp.com");

Server.Transfer():
- HttpServerUtility.Transfer() method also used to send the user from one page to the other
page.

- Ex: Server.Transfer("Page2.aspx");

- It doesn’t involve the browser. Instead of sending a redirect message back to the browser,
ASP.NET simply starts processing the new page as though the user had originally requested that
page.

- You can’t use Transfer() to send the user to another website or to a non-ASP.NET page like
HTML page.

- The Transfer() method allows you to jump only from one ASP.NET page to another, in the same web application.

- When you use Transfer(), the user won’t have any idea that another page has taken over,
because the browser will still show the original URL. Means the URL will not change.



0 comments

Post a Comment