ASP.net 不填充 action="";发布时的服务器表单

ASP.net doesn#39;t populate action=quot;quot; of the server form when released(ASP.net 不填充 action=;发布时的服务器表单)

本文介绍了ASP.net 不填充 action="";发布时的服务器表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ASP.net webforms 站点,在母版页中有一个服务器表单,因为所有页面都需要它.

I have an ASP.net webforms site, with a server form in the masterpage, as all pages require it.

调试时,action 参数在运行时与 id 一起填充,但是当使用 IIS7 部署在我的服务器上时,它不会出现......但仍然有效.它不会导致站点问题,但会导致我的 W3C HTML5 验证失败,因为它需要填充.

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.

调试源:

<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 %>" 来获取路径名,但它不起作用.

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?

谢谢.

更新

好的,为了解决答案中指出的问题,我只是在Masterpage Page_Load上设置了Form.Action,终于得到了W3C的绿灯!

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!

注意:我使用的是 Intelligencia Rewriter,但您可以使用 Request.Url

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;
    }
}

推荐答案

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.

这篇关于ASP.net 不填充 action="";发布时的服务器表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:ASP.net 不填充 action="";发布时的服务器表单

基础教程推荐