c# - IHttpModule Response.Filter Write with No Close HTML -



c# - IHttpModule Response.Filter Write with No Close HTML -

i wrote custom ihttpmodule causing issues when there no closing tag in source. have ran across few pages in cms running .aspx page used more handler , forgoes closing html give response via ajax user.

here source:

public class hidemodule : ihttpmodule { public void dispose() { //empty } public void init(httpapplication app) { app.releaserequeststate += new eventhandler(installresponsefilter); } // --------------------------------------------- private void installresponsefilter(object sender, eventargs e) { httpresponse response = httpcontext.current.response; string filepath = httpcontext.current.request.filepath; string fileextension = virtualpathutility.getextension(filepath); if (response.contenttype == "text/html" && fileextension.tolower() == ".aspx") response.filter = new pagefilter(response.filter); } } public class pagefilter : stream { stream responsestream; long position; stringbuilder responsehtml; public pagefilter (stream inputstream) { responsestream = inputstream; responsehtml = new stringbuilder (); } //other overrides here public override void write(byte[] buffer, int offset, int count) { string strbuffer = system.text.utf8encoding.utf8.getstring (buffer, offset, count); regex eof = new regex ("</html>", regexoptions.ignorecase); if (!eof.ismatch (strbuffer)) { responsehtml.append (strbuffer); } else { responsehtml.append (strbuffer); string finalhtml = responsehtml.tostring(); //do replace here byte[] info = system.text.utf8encoding.utf8.getbytes(finalhtml); responsestream.write(data, 0, data.length); } } #endregion }

as can see great because replace lastly time write called, if output doesn't have closing html tag, blammo.

my best alternative not add together new filter if closing html not found. don't think can intercept total stream early. failing there way observe write @ end of stream besides looking closing html tag?

thanks in advance.

well, if it's webforms, should able in installresponsefilter function:

if(application.context.currenthandler system.web.ui.page && application.request["http_x_microsoftajax"] == null && application.request.params["_tsm_combinedscripts_"] == null) { response.filter=new pagefilter(response.filter); }

c# asp.net ihttpmodule response.filter

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -