日期:2014-05-18 浏览次数:20422 次
namespace DOTA.Browser { public class FormRewriterControlAdapter : System.Web.UI.Adapters.ControlAdapter { protected override void Render(HtmlTextWriter writer) { base.Render(new RewriteFormHtmlTextWriter(writer)); } } public class RewriteFormHtmlTextWriter : HtmlTextWriter { public RewriteFormHtmlTextWriter(HtmlTextWriter writer) : base(writer) { this.InnerWriter = writer.InnerWriter; } public RewriteFormHtmlTextWriter(TextWriter writer) : base(writer) { this.InnerWriter = writer; } public override void WriteAttribute(string name, string value, bool fEncode) { if (name == "action") { HttpContext context = HttpContext.Current; if (context.Items["ActionAlreadyWritten"] == null) { value = context.Request.ServerVariables["HTTP_X_REWRITE_URL"] ?? context.Request.RawUrl; context.Response.Write(value); //这里执行了,源代码里有,是Request.RawUrl的值。 HTTP_X_REWRITE_URL 这个是空的. context.Items["ActionAlreadyWritten"] = true; } } base.WriteAttribute(name, value, fEncode); } } }
<browser refID="Default"> <controlAdapters> <adapter controlType="System.Web.UI.HtmlControls.HtmlForm" adapterType="DOTA.Browser.FormRewriterControlAdapter" /> </controlAdapters> </browser>