ASP.net 4.0 Webforms 路由回发问题
我们使用 asp.net 4.0 和 Web 表单路由来创建友好的 URL。
路由工作正常,只是没有将正确的“操作”值分配给母版页中任何具有多个级别的路由的表单元素。
例如,使用 .../customer/12345 浏览到的路由 ( customer/{customerid} ) 仅在表单的“action”属性中显示 12345。问题是它不完整,任何回发都会失败并给出错误“不允许用于访问路径的 HTTP 动词 POST”如果我将操作更新为“customer/12345”(使用 Firebug),则回发工作正常。
当使用像客户/客户这样的静态路由时,它甚至会出错,它只将“客户”而不是“客户/客户”作为表单的操作值。基本上,只将路线的最后一段而不是整个路线放入操作属性中。为什么?
关于如何纠正这个问题有什么想法吗?
We are using asp.net 4.0 and routing with web forms to create friendly urls.
The routing is working fine except that the correct "action" value is not being assigned to the form element in the master page for any route that has multiple levels.
For example, the route ( customer/{customerid} ) when browsed to with .../customer/12345 only displays 12345 in the "action" attribute of the form. The issue with this is that it isn't complete and any postback fails and gives an error "The HTTP verb POST used to access path is not allowed" If I updates the action as "customer/12345" (using Firebug), the postback works fine.
It even errors when using static routes like customer/customer, it only puts "customer" and not "customer/customer" as the action value of the form. Basically, only putting the last piece of the route into the action attribute instead of the whole route. Why?
Any ideas on how to correct this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过在
Page_Load
事件中将表单操作重写为form1.Action = Request.Url.PathAndQuery;]
来解决此问题You can work around this by overiding the form action as
form1.Action = Request.Url.PathAndQuery;]
in thePage_Load
event请参阅此相关主题。
它使用
Request.RawUrl
而不是Request.Url.PathAndQuery
,后者似乎返回相同的值。See this related Topic.
It uses
Request.RawUrl
instead ofRequest.Url.PathAndQuery
, which seams to return the same value.