前不久做了一下
Rewriter二级域名和URL重写,结果发现好是好,但是,查看HTML源代码中,发现了FORM中的地址还是
<form name="aspnetForm" method="post" action="../aa/bb.aspx?cid=2" id="aspnetForm">
有什么办法让form action和重写的URL一样?

 

找了好一会,找到解决方案

 

 

public class BasePage:Page
    {
        protected override void Render(HtmlTextWriter writer)
        {
            writer = new FormFixer(writer);
            base.Render(writer);
        }

        internal class FormFixer : HtmlTextWriter
        {
            private bool _isInForm = false;

            public FormFixer(System.IO.TextWriter writer) : base(writer) { }

            public FormFixer(System.IO.TextWriter writer, string tagString) : base(writer, tagString) { }

            public override void WriteBeginTag(string tagName)
            {
                if (string.Compare(tagName, "form") != 0)
                    this._isInForm = true;
                base.WriteBeginTag(tagName);
            }

            public override void WriteAttribute(string name, string value, bool fEncode)
            {
                if (this._isInForm && name.Equals("action"))
                    value = HttpContext.Current.Request.RawUrl;
                base.WriteAttribute(name, value, fEncode);
            }
        }
    }

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐