开发者

What is the difference between Server.Transfer and Response.Redirect?

What is the difference between Server.开发者_如何学JAVATransfer and Response.Redirect?


Response.Redirect sends a '302 Moved Temporarily' response to the client, the client browser will then issue a request to that location.

Server.Transfer transfers the control from one page to the other on the server side, so the original Request and Response buffer streams remain as they are at the point the transfer is done.

This means that Response.Redirect requires a round trip to the client but a Server.Transfer does not. The other difference is that the Server.Transfer appears to the browser as the original url... e.g. consider Page1.aspx does a server.transfer to page2.aspx, In this case Page1.aspx shows in the address bar even though they are actually being shown Page2.aspx. If instead Page1.aspx did a Response.Redirect then Page2.aspx would be shown.

So depending on what you want to optimise Response.Redirect are better if you want to support bookmarking of pages correctly and Server.Transfers are better if you want to minimise client round trips to the server.

Oh, and do check out http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=15 it describes this much better with the caveats.


Server.Transfer() only works with pages from your site, it means that the server starts rendering a new page from scratch.

Response.Redirect() is a normal redirection, which works with any URL.


Response.Redirect should be used :

  • if we want to redirect the request to same server or to some other web server
  • if we don't care about causing additional roundtrips to the server on each request

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

  • if we want our users to be able to see the new redirected URL where he is redirected in his browser

  • Response.Redirect is more user-friendly, as the site visitor can bookmark the page that they are redirected to.

    Server.Transfer should be used :


  • if we want to transfer current page request to another .aspx page on the same server not on the another server
    Example if your server is www.yahoo.com you cannot use server. Transfer to move to www.microsoft.com
  • if we want to preserve server resources and avoid the unnecessary roundtrips to the server
  • if we want to preserve Query String and Form Variables -if we don't need to show the real URL where we redirected the request in the users Web Browser


Server.Transfer gives you an options to set parameter values to the destination page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜