且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在HTTP模块关闭html标记之前注入HTML

更新时间:2023-12-05 21:28:34

您应该使用 HttpContext.Response.Filter

勾选此MSDN文档页面:

Check this MSDN documentation page:

这很老的文章应该澄清这太:

This very old article should clarify this too:

汇总,你需要创建一个流实现包装原始之一 HttpContext.Current.Response.Filter 来了。

Summarizing, you need to create a Stream implementation wrapping the original one coming in HttpContext.Current.Response.Filter.

为了在文档的某些部分注入HTML,您只需字节转换为字符串,并使用 String.IndexOf 或常规前pression你要去,如果你在整个code线是到deremine。

In order to inject HTML in some part of the document, you simply need to convert bytes into a string and using a String.IndexOf or a regular expression you're going to deremine if you're in the whole code line.

之后,只需拼接,修改或替换字符串获得并把它放在包裹流中的原始默认响应滤波器来了。

After that, just concatenate, modify or replace obtained string and put it in the wrapped Stream coming in the original, default response filter.