或相反亦然。
更新: 嗯,让我们假设我有一个购物车应用程序,用户点击结帐按钮。 我想要做的下一件事是将用户发送到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.
更多推荐
发布评论