您现在的位置:龙卷风首页 ›› 网络编程 ›› 阅读文章

ASP.NET:url重写之后form表单提交出错

url重写后form出错如何修正?

在ASP.NET中,url重写之后,系统自动生成的form属性action中的地址就错了,因为地址重写之后的相对路径发生了变化。为了修正这个错误,需要对form的action属性进行修改。方法之一是取消系统自动生成action属性的功能。

新建一个类,用来做无action得form。

    public class Form : System.Web.UI.HtmlControls.HtmlForm
    {
        protected override void RenderAttributes(HtmlTextWriter writer)
        {
            writer.WriteAttribute("name", this.Name);
            base.Attributes.Remove("name");

            writer.WriteAttribute("method", this.Method);
            base.Attributes.Remove("method");

            this.Attributes.Render(writer);

            base.Attributes.Remove("action");

            if (base.ID != null)
                writer.WriteAttribute("id", base.ClientID);
        }
    }

 

然后在页面中注册成一个用户控件:

//我这里是把这个类放在一个assembly中,命名空间是NT.Web
Register TagPrefix="skm" Namespace="NT.Web" Assembly="NT.Web"

然后把页面中正常的form改写如下


作者 不见不散 本文仅代表作者观点,与龙卷风资讯网立场无关。

我来说两句

内容/Content