Response.Redirect和Server.Transfer [英] Response.Redirect and Server.Transfer

查看:88
本文介绍了Response.Redirect和Server.Transfer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Response.Redirect和Server.Transfer.Rhere之间的区别我们必须使用这两个示例。

解决方案

Response.Redirect 涉及到服务器的额外往返,而 Server.Transfer 通过避免额外的往返来节省服务器资源。 Server.Transfer 只是通过直接与服务器通信来改变页面的焦点。



在这里,阅读:

Response.Redirect [< a href =http://msdn.microsoft.com/en-us/library/a8wa7sdt%28v=vs.100%29.aspxtarget =_ blanktitle =New Window> ^ ]

Vs

Server.Transfer [ ^ ]



Response.Redirect
将HTTP代码302向下发送到用户浏览器以及所需页面的新URL位置。 HTTP代码302实际上意味着'请求的资源暂时驻留在不同的URI下'。

但是
Server.Transfer 不会发起另一个请求服务器,但原始请求只是被重写并转移到同一台服务器上的其他页面。



然后这些:

Server.Transfer和Response.Redirect有什么区别方法? [ ^ ]

差异Server.Transfer()和Response.Redirect() [ ^ ]





摘要:



    Response.Redirect 应在以下情况下使用:



  • 我们要将请求重定向到某些我们的服务器或其他一些Web服务器上的纯HTML页面
  • 我们不关心在每次请求时导致额外的往返服务器
  • 我们不需要保留查询字符串和来自原始请求的表单变量
  • 我们希望我们的用户能够看到他重定向到的新重定向URL如果需要,可以使用rowser(并且能够将其加入书签)
  • Server.Transfer



  • 我们希望保留服务器资源并避免不必要的往返服和表格变量(可选)
  • 我们不需要在用户Web浏览器中显示我们重定向请求的真实URL


< blockquote> 应在以下情况下使用Response.Redirect:



我们要将请求重定向到一些纯HTML我们的服务器或其他网络服务器上的页面



我们不关心在每次请求时导致额外的往返服务器



我们不需要保留原始请求中的查询字符串和表单变量



我们希望我们的用户能够看到新的redi在他的浏览器中重定向的网址(如果必要,可以将其加入书签)



在以下情况下应使用Server.Transfer:



我们想将当前页面请求转移到同一台服务器上的另一个.aspx页面



我们希望保留服务器资源并避免不必要的往返服务器



我们要保留查询字符串和表单变量(可选)



我们不需要显示我们在用户Web浏览器中重定向请求的真实URL


以下是主要区别他们之间: -
$ b $b√Response.Redirect向浏览器发送消息,说它要移动到某个

不同的页面,而server.transfer不向浏览器发送任何消息

而是直接从服务器本身重定向用户。所以在server.transfer

没有往返,而response.redirect有往返,因此在服务器上加载

a。
$ b $b√使用Server.Transfer,你无法重定向到与服务器本身不同的地方。

例如,如果您的服务器是www.yahoo.com,您可以使用server.transfer移动

到www.microsoft.com但是你可以转到www.yahoo.com/travels,即

在网站内。这种跨服务器重定向只能使用

Response.redirect。
$ b $b√使用server.transfer,您可以保留您的信息。它有一个参数

,称为preserveForm。因此现有的查询字符串等将能够在

调用页面中。在response.redirect中你可以维持状态,但是有很多缺点。


Difference between Response.Redirect and Server.Transfer.Where we have to use these two with example.

解决方案

Response.Redirect involves an extra round-trip to the server whereas Server.Transfer conserves server resources by avoiding that extra round-trip. Server.Transfer just changes the focus of the page by directly communicating with server.

Here, read:
Response.Redirect[^]
Vs
Server.Transfer[^]

Response.Redirect
sends HTTP code 302 down to the users browser along with the new URL location of the wanted page. HTTP Code 302 actually means ' The requested resource resides temporarily under a different URI'.
BUT
Server.Transfer do not initiates another request to the server, but the original request is simply rewritten and transfered to some other page on the same server.

Then these:
What is the difference between Server.Transfer and Response.Redirect methods? [^]
Difference between Server.Transfer() and Response.Redirect()[^]


Summary:

    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


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


Following are the major differences between them:-
√ Response.Redirect sends message to the browser saying it to move to some
different page, while server.transfer does not send any message to the browser
but rather redirects the user directly from the server itself. So in server.transfer
there is no round trip while response.redirect has a round trip and hence puts
a load on server.
√ Using Server.Transfer you can not redirect to a different from the server itself.
Example if your server is www.yahoo.com you can use server.transfer to move
to www.microsoft.com but yes you can move to www.yahoo.com/travels, i.e.
within websites. This cross server redirect is possible only using
Response.redirect.
√ With server.transfer you can preserve your information. It has a parameter
called as "preserveForm". So the existing query string etc. will be able in the
calling page. In response.redirect you can maintain the state, but has
lot of drawbacks.


这篇关于Response.Redirect和Server.Transfer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆