19

Possible Duplicates:
Response.Redirect vs. Server.Transfer
Server.Transfer Vs. Response.Redirect

What is the difference between response.redirect and server.transfer? Only one difference i know is: In response.redirect the browser url changes to targeted page as well as in server.transfer the url remains same! any other difference?

Community
  • 1
  • 1
SMK
  • 2,098
  • 2
  • 13
  • 21

4 Answers4

59

Response.Redirect should be used when:

  • we want to redirect the request to some plain HTML pages on our server or to some other web server

  • we don't care about causing additional roundtrips to the server on each request

  • we do not need to preserve Query String and Form Variables from the original request

  • we want our users to be able to see the new redirected URL where he is redirected in his browser (and be able to bookmark it if its necessary)

Server.Transfer should be used when:

  • we want to transfer current page request to another .aspx page on the same server

  • we want to preserve server resources and avoid the unnecessary roundtrips to the server

  • we want to preserve Query String and Form Variables (optionally)

  • we don't need to show the real URL where we redirected the request in the users Web Browser

Pit Digger
  • 9,618
  • 23
  • 78
  • 122
  • transfer current page request to another .aspx page on the same server. y can't it redirect to the another server? Can u explain this in detail. –  Feb 04 '13 at 07:43
13

Response.Redirect() sends a redirection header to the client, and the client itself requests the new page.

Server.Transfer() only stops rendering the current page and starts rendering another one. The client is none the wiser.

That's why Server.Transfer() cannot be used to redirect to pages served by another server.

Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
  • So we not use querry string or some thing else which is client specific in server.transfer? – SMK Jul 21 '11 at 15:50
  • @Shoaib, absolutely. The client is not involved in `Server.Transfer()` in any way, and doesn't know it took place. That's why the URL in the browser doesn't change. – Frédéric Hamidi Jul 21 '11 at 15:52
2

Server.Transfer is more efficient because with Response.Redirect you tell the browser to make another request (another network roundtrip) whil Server.Transfer is "server-internal"...

Yahia
  • 69,653
  • 9
  • 115
  • 144
0

The Form data is transferred on Server.Transfer, but not on Response.Redirect, one other difference. Also, if not mistaken, Server.Transfer works on the same server, not cross-server pages.

AD.Net
  • 13,352
  • 2
  • 28
  • 47