为什么要Server.Transfer的连续调用更改URL? [英] Why does consecutive calls to Server.Transfer change the url?
问题描述
我用 Server.Transfer的
单击按钮时加载其他页面的内容。这将按预期和网址保持不变。但是,如果我尝试在一个按钮在第二页点击加载第三页,网址更改为第二页。我希望它保持第一页的URL。
例如:
-
Page1.aspx的
负载。- 地址:
... / Page1.aspx的
- 内容:
Page1.aspx的
- 地址:
-
Server.Transfer的(〜/ Page2.aspx)
按钮点击。- 地址:
... / Page1.aspx的
- 内容:
Page2.aspx
- 地址:
-
Server.Transfer的(〜/ Page3.aspx)
按钮点击- 地址:
... / Page2.aspx
- 内容:
Page3.aspx
- 地址:
为什么在第三步中的URL改变?
当你调用 Server.Transfer的()
第1页的执行停止,第2页执行内而不是相同的HTTP请求。的第2页(Page2.aspx)随后以同样的方式,这将是对直接向它的URL的任何正常请求执行的,所以该形式的操作被设置为自己的URL(尽管从<$ C被称为$ C> Server.Transfer的())。
如果这不是那么当表单提交,将张贴到Page1.aspx的(如你期望),但当前页不一定含有相同的控制,并能够处理该请求的情况下。对>
I'm using Server.Transfer
to load the contents of another page when clicking a button. This works as expected and the url stays the same. However, if I try to load a third page at the click of a button in the second page, the url changes to that of the second page. I would expect it to keep the url of the first page.
Example:
Page1.aspx
loads.- Url:
.../Page1.aspx
- Content:
Page1.aspx
- Url:
Server.Transfer("~/Page2.aspx")
on button click.- Url:
.../Page1.aspx
- Content:
Page2.aspx
- Url:
Server.Transfer("~/Page3.aspx")
on button click- Url:
.../Page2.aspx
- Content:
Page3.aspx
- Url:
Why does the url change in the third step?
When you call Server.Transfer()
the execution of the 1st page is stopped and the 2nd page is executed instead within the same HTTP request. The 2nd page (Page2.aspx) is then executed in the same way that it would be for a any normal request made directly to its URL, so the action of the form is set to its own URL (despite being called from Server.Transfer()
).
If this was not the case then when the form is submitted it would post to Page1.aspx (as you are expecting), but this page would not necessarily contain the same controls and be able to process the request.
这篇关于为什么要Server.Transfer的连续调用更改URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!