posted by 네코냥이 2013. 12. 30. 09:59

원본

http://www.c-sharpcorner.com/UploadFile/0c1bb2/response-redirect-and-server-transfer-in-Asp-Net/

원본 페이지: 

Response.Redirect Vs Server.Transfer in ASP.pdf


Background
 
Server.Transfer and Response.Redirect both are used to navigate from one page to another page, but there are some differences between them depending on the pages that we want to navigate to.
 
So let us learn step-by-step.
  • Response.Redirect

The Response.Redirect object transfers the page permanently to the next page and ends the processing of the first page and the new page processing continues on the redirected page but also it sends a command back to the browser; because of this one extra unnecessary round trip happens.

Suitable Uses

The suitable uses are:

  • to redirect the page from the same as well as a different web server.
  • don't care about causing additional round trips to the server on each request.
  • do not need to preserve the Query String and Form Variables from the original request.
  • want our users to be able to see the new redirected URL, where the page is redirected.
  • want to bookmark the page.

 

  • Server.Transfer

 

Server.Transfer navigates the pages within the same application or within the same server, the page is still in memory that can read the values directly from page2 on page1, in other words by using server.Transfer the page is not redirected permanently.

Suitable Uses

The suitable uses are:

  • to transfer the current page request to another .aspx page on the same server.
  • to preserve server resources and avoid the unnecessary round trips to the server.
  • to  preserve the Query String and Form Variables.
  • don't need to show the real URL of where we redirected the request in the user's Web Browser.
  • don’t want to bookmark the pages.
To demonstrate this, let us create one web application as in the following:
  1. "Start" - "All Programs" - "Microsoft Visual Studio 2010".
  2. "File" - "New WebSite" - "C#" - "Empty Web Site" (to avoid adding a master page).
  3. Provide the Project name such as "ResponseVsServer" or another as you wish and specify the location.
  4. Then right-click on Solution Explorer then seelct "Add New Item" - "Default.aspx" page (two web pages).