Response.Redirect和Server.Transfer面对页面刷新时的小区别

今天用Server.Transfer时遇到一个小问题,没有搜到相应的贴子记录,所以在此记录一下:

Server Transfer

  1. Client Request Page HelloWorld.ASPX
  2. Server.Transfer -> Server send a different page to the client
  3. Client Receives Page still thinking it's HelloWorld.ASPX.
  4. Client's URL (Address bar) remains HelloWorld.ASPX since the page was sent on the server side and the client doesn't know a different page was sent.

Response.Redirect

  1. Client Requests Page HelloWorld.ASPX
  2.  Response.Redirect -> Server sends a HTTP header informing that the user should redirect.
  3.  Client sees the redirect notice and requests AnotherPage.ASPX
  4.  Server sends AnotherPage.ASPX
  5. Client's URL (address bar) shows AnotherPage.ASPX

Server Transfer使用特殊注意事项:

  假如从A页面Transfer到B页面之后,在B页面刷新的话,此时会重新回到A页面的后台,进入A页面的点击事件然后再transfer到B页面。

如果A页面的点击事件有对数据库操作的话,此时就会再次操作数据库。为了数据安全还是Response.Redirect比较好。

你可能感兴趣的:(response)