It is easier to modify the HTML content of the full-station output page than the previous one, "ASP. NET uses page adapters and overrides render"
http://blog.csdn.net/lrxin/article/details/40861039
Configuration method:
<add name= "Fileeditmodule" type= "Framework.fileeditmodule, Framework"/>
<pre name= "code" class= "CSharp" >public class FileEditModule:System.Web.IHttpModule {public void Dispose () {} public void Init (HttpApplication application) {application. EndRequest + = new EventHandler (application_endrequest); } void Application_EndRequest (object sender, EventArgs e) {try {HTTPA pplication application = (HttpApplication) sender; Uri URL = Application. Request.url; If the request URL needs to be verified string[] SS = Application. Request.FilePath.Split ('. '); string extension = Ss[ss. LENGTH-1]; Extension = extension. ToLower (); string[] Extensions = new string[] {"ashx", "aspx", "asmx"} ; if (extensions. Contains (extension)) {String html = getrenderhtml (NULL, application. Response); //.... Manipulate the HTML application. Response.clearcontent (); Application. Response.Write (HTML); }} catch (Exception ex) {}}public string getrenderhtml (HtmlTextWriter writer, HttpResponse Response) {//var Response = this. Page.Response; Response.Output is actually a httpwriter,response.outputstream is actually httpresponsestream,object.referenceequals ( Response.Output, (Response.outputstream as Httpresponsestream). _writer) True bindingflags bind = bindingflags.no Npublic | BindingFlags.Instance | Bindingflags.ignorecase | Bindingflags.getfield; Because httpwriter._charbuffer the length of this character array is 1024,//So presumably, once a string of more than 1024 will create a ihttpresponseelement,//And then add to the HT Each element of the Tpwriter._buffers,httpwriter._buffers implements the Ihttpresponseelement interface,//the specific type may be Httpresponseunmanagedbufferelem Ent,httpsubstblockresponseelement and other types ArrayList arr = (ArrayList) Response.Output.GetTYpe (). GetField ("_buffers", bind). GetValue (Response.Output); Assembly Systemweb = Assembly.Load ("system.web, version=2.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a"); Type type = Systemweb.gettype ("System.Web.IHttpResponseElement"); MethodInfo method = Type. GetMethod ("GetBytes"); StringBuilder sb = new StringBuilder (5000); Iterate through each buffer, get an array of characters stored in buffer, and convert to a string for (int i = 0; i < arr. Count; i++) {byte[] buffer = (byte[]) method. Invoke (Arr[i], NULL); Use the current encoding to derive the string SB that has been stored in the httpwriter._buffers. Append (Response.ContentEncoding.GetString (buffer)); }//Get Httpwriter character array buffer char[] Charbuffer = (char[]) Response.Output.GetType (). GetField ("_charbuffer", bind). GetValue (Response.Output); int charbufferlength = (int) Response.Output.GetType (). GetField ("_charbufferlength", bind). GetValue (Response.Output); int CHArbufferfree = (int) Response.Output.GetType (). GetField ("_charbufferfree", bind). GetValue (Response.Output); Charbufferlength-charbufferfree equals the number of characters that the character array buffer has used for (int i = 0; i < Charbufferlength-charbufferfree ; i++) {sb. Append (Charbuffer[i]); } string html = sb. ToString (); return HTML; } }
ASP. NET uses HttpModule to modify the HTML content of the dynamic page of the entire station output, without confusion