我什么时候使用Server.Transfer通过PostBackURL?(When would I use Server.Transfer over PostBackURL?)

编程入门 行业动态 更新时间:2024-10-27 09:38:50
什么时候使用Server.Transfer通过PostBackURL?(When would I use Server.Transfer over PostBackURL?)

或相反亦然。

更新: 嗯,让我们假设我有一个购物车应用程序,用户点击结帐按钮。 我想要做的下一件事是将用户发送到Invoice.aspx页面(或类似页面)。 当用户点击结账时,我可以将Button.PostBackURL = "Invoice.aspx"

或者我可以做

Server.Transfer("Invoice.aspx")

(我也改变了标题,因为该方法被称为Transfer而不是TransferURL)

Or vice versa.

Update: Hmm, let's assume I have a shopping cart app, the user clicks on the Checkout button. The next thing I want to do is send the user to a Invoice.aspx page (or similar). When the user hits checkout, I could Button.PostBackURL = "Invoice.aspx"

or I could do

Server.Transfer("Invoice.aspx")

(I also changed the title since the method is called Transfer and not TransferURL)

最满意答案

Server.TransferURL不会导致HTTP请求/响应的往返。 只要浏览器知道它只收到一个文档,地址栏就不会更新。 Server.Transfer也保留执行上下文,所以脚本“继续前进”而不是“重新开始”。 PostbackURL确保一个HTTP请求,导致一个可能不同的URL并且当然招致网络延迟成本。

通常,当您试图“在两者之间做出决定”时,这意味着您最好使用PostbackURL。

随意扩大你的问题与细节,我们可以看看你的确切需求。

Server.TransferURL will not result in a roundtrip of HTTP request/response. The address bar will not update, as far as the browser knows it has received only one document. Server.Transfer also retains execution context, so the script "keeps going" as opposed to "starts anew". PostbackURL ensures an HTTP request, resulting in a possibly different URL and of course incurring network latency costs.

Usually when you are attempting to "decide between the two" it means you are better off using PostbackURL.

Feel free to expand your question with specifics and we can look at your precise needs.

更多推荐

本文发布于:2023-08-06 20:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1455330.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:什么时候   Server   PostBackURL   Transfer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!