我有一个 ASP.net Web 表单站点,母版页中有一个服务器表单,因为所有页面都需要它。
调试时,action
参数在运行时与 id
一起填充,但是当使用 IIS7 部署在我的服务器上时,它不会出现......但仍然有效。它不会导致网站问题,但会导致我的 W3C HTML5 验证失败,因为需要填充它。
调试源:
<form method="post" action="index.aspx" id="aspnetForm">
实时源:母
<form method="post" action="" id="aspnetForm">
版页中的表单声明:
<form runat="server">
.. some divs
</form>
我知道表单标记没有定义 ID/操作等,因为 ASP 在运行时配置默认值,这很好,尽管由于某种原因它在我的服务器上弄乱了。我尝试使用 action="<% Path etc %>"
来获取路径名称,但它不起作用。
我做错了什么?我是否遗漏了某些内容,或者在母版页中使用表单只是一种不好的做法?
谢谢。
更新
好的,为了解决答案中指出的问题,我只是在Masterpage Page_Load上设置了Form.Action,终于得到了W3C的绿灯!
注意:我使用的是 Intelligencia Rewriter,但您可以使用 Request.Url 提取 URL
public partial class myMasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
Form.Action = Intelligencia.UrlRewriter.RewriterHttpModule.RawUrl;
}
}
I have an ASP.net webforms site, with a server form in the masterpage, as all pages require it.
When debugging the action
parameter is populated at runtime along with the id
, but when deployed on my server with IIS7 it doesn't appear... but still works. It's not causing the site issues, but its making my W3C HTML5 validation fail, as it needs to be populated.
Debug source:
<form method="post" action="index.aspx" id="aspnetForm">
Live source:
<form method="post" action="" id="aspnetForm">
Form declaration in masterpage:
<form runat="server">
.. some divs
</form>
I know the form tag doesnt have ID/action defined etc, because ASP configures the default at runtime and thats fine, although for some reason it messes up on my server. I've tried using the action="<% Path etc %>"
, to get the path name but it doesn't work.
What am I doing wrong? Am I missing something, or is it just bad practise to use a form in a masterpage?
Thanks.
Update
Ok, to solve the issue pointed out in the answer I just set the Form.Action on the Masterpage Page_Load, finally got that W3C green light!
Note: I'm using Intelligencia Rewriter, but you can pull the URL using Request.Url
public partial class myMasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
Form.Action = Intelligencia.UrlRewriter.RewriterHttpModule.RawUrl;
}
}
发布评论
评论(2)
ASP.NET 4.0?如果是这样,这就是您的答案: http://www.asp.net/whitepapers /aspnet4/break-changes#0.1__Toc256770154;这不是一本容易阅读的书,而且我自己也不熟悉,所以您可能应该阅读它并了解它如何影响您的网站。
asp.net 4.0? If so, here's your answer: http://www.asp.net/whitepapers/aspnet4/breaking-changes#0.1__Toc256770154; It's not an easy read, and I'm not familiar myself, so you should probably read it and see how that affects your site.
我刚刚看到你的帖子,有完全相同的经历。在我看来,这是不直观的设计行为,会给大多数试图掌握兼容 HTML5 的 ASP.NET 新手开发人员带来困惑。
无论如何,经过一些篡改后,可以使用以下方法轻松解决问题。 无需篡改 web.config - 谢天谢地!
在母版页中,添加此代码段(或者在出现此问题的默认页面中,如果您不使用母版页)
I just saw your post having had exactly the same experience. In my opinion this is unintuitive by-design behaviour that will bring confusion to the majority of newer ASP.NET developers trying to grasp compliant HTML5.
Anyway after some tampering the problem can be fixed very easily using the following approach. There is no need to tamper with the web.config - thankfully!
In the Master page, add this snippet (or in the default page where this problem arises, if you're not using a master page)