The specific approach is as follows: You can override the default HtmlTextWriter method by customizing the page base class, overriding the property output WriteAttribute (string name, string value, bool encode) method, when the output action is Casts the value of the Action property to the current virtual URL (HttpContext.Current.Request.RawUrl, ~/showvisasall_ (\w+) \.aspx)
The last thing is to have all the pages call the base class and modify the web.config.
<!--Openlab.Controls.OLPage is the base class for the page, Openlab.controls is the DLL that contains the base class-->
<pages pagebasetype= "Openlab.Controls.OLPage, Openlab.controls"/>
Complete code with page base class (reference CS code complete):
Copy Code code as follows:
Using System;
Using System.IO;
Using System.Web;
Using System.Web.UI;
Namespace Openlab.controls
... {
/**////<summary>
Page base class
</summary>
public class Olpage:page
... {
Public Olpage ()
... {
}
Render#region Render
/**////<summary>
Overrides the default HtmlTextWriter method, modifying the Value property in the form tag so that its value is the overridden URL instead of the real URL.
</summary>
<param name= "Writer" ></param>
protected override void Render (HtmlTextWriter writer)
... {
If (writer is System.Web.UI.Html32TextWriter)
... {
writer = new Formfixerhtml32textwriter (writer. Innerwriter);
}
Else
... {
writer = new Formfixerhtmltextwriter (writer. Innerwriter);
}
Base. Render (writer);
}
#endregion
}
Formfixers#region formfixers
Formfixerhtml32textwriter#region Formfixerhtml32textwriter
Internal class FormFixerHtml32TextWriter:System.Web.UI.Html32TextWriter
... {
private string _url; Fake URL
Internal Formfixerhtml32textwriter (TextWriter writer): Base (writer)
... {
_url = HTTPCONTEXT.CURRENT.REQUEST.RAWURL;
}
public override void WriteAttribute (string name, string value, bool encode)
... {
If the current output property is a form-marked Action property, the value is replaced with the overridden false URL
if (_url!= null && string.compare (name, action, true) = = 0)
... {
value = _url;
}
Base. WriteAttribute (name, value, encode);
}
}
#endregion
Formfixerhtmltextwriter#region Formfixerhtmltextwriter
Internal class FormFixerHtmlTextWriter:System.Web.UI.HtmlTextWriter
... {
private string _url;
Internal Formfixerhtmltextwriter (TextWriter writer): Base (writer)
... {
_url = HTTPCONTEXT.CURRENT.REQUEST.RAWURL;
}
public override void WriteAttribute (string name, string value, bool encode)
... {
if (_url!= null && string.compare (name, action, true) = = 0)
... {
value = _url;
}
Base. WriteAttribute (name, value, encode);
}
}
#endregion
#endregion
}