Server.Transfer Vs. Response.Redirect

前端 未结 16 2564
夕颜
夕颜 2020-11-22 14:38

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

  • What are advantages and disadvantages of each?
  • When is one
16条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 15:39

    Response.Redirect involves an extra round trip and updates the address bar.

    Server.Transfer does not cause the address bar to change, the server responds to the request with content from another page

    e.g.

    Response.Redirect:-

    1. On the client the browser requests a page http://InitiallyRequestedPage.aspx
    2. On the server responds to the request with 302 passing the redirect address http://AnotherPage.aspx.
    3. On the client the browser makes a second request to the address http://AnotherPage.aspx.
    4. On the server responds with content from http://AnotherPage.aspx

    Server.Transfer:-

    1. On the client browser requests a page http://InitiallyRequestedPage.aspx
    2. On the server Server.Transfer to http://AnotherPage.aspx
    3. On the server the response is made to the request for http://InitiallyRequestedPage.aspx passing back content from http://AnotherPage.aspx

    Response.Redirect

    Pros:- RESTful - It changes the address bar, the address can be used to record changes of state inbetween requests.

    Cons:- Slow - There is an extra round-trip between the client and server. This can be expensive when there is substantial latency between the client and the server.

    Server.Transfer

    Pros:- Quick.

    Cons:- State lost - If you're using Server.Transfer to change the state of the application in response to post backs, if the page is then reloaded that state will be lost, as the address bar will be the same as it was on the first request.

提交回复
热议问题