欢迎来到天天文库
浏览记录
ID:38665847
大小:30.50 KB
页数:7页
时间:2019-06-17
《对HTTP输入、输出内容做任意的拦截和替换》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、可以对http最终输入、输出内容做任意的替换,代码如下:usingSystem;usingSystem.Collections;usingSystem.Configuration;usingSystem.Text.RegularExpressions;usingSystem.Web;usingSystem.Xml;usingSystem.Xml.Serialization;usingSystem.IO;usingSystem.Text;namespaceCnlamar.Web.HttpModule{ publicclassTextR
2、eplace:IHttpModule { publicvirtualvoidDispose() { } publicvirtualvoidInit(HttpApplicationcontext) { context.ReleaseRequestState+=newEventHandler(this.context_ReleaseRequestState); } publicvoidcontext_ReleaseRequestState(objects
3、ender,EventArgse) { HttpApplicationhttpApplication=(HttpApplication)sender; if(httpApplication.Response.ContentType.ToLower().IndexOf("image")<=-1) { TextReplaceFiltertextReplaceFilter=newTextReplaceFilter(httpApplication.Response.Filt
4、er); textReplaceFilter.Encoding=System.Text.Encoding.GetEncoding(httpApplication.Response.ContentEncoding.BodyName); textReplaceFilter.ReplaceRules=TextReplaceConfiguration.GetConfig().Rules; httpApplication.Response.Filter=textReplaceFilter;
5、 } } } classTextReplaceFilter:Stream { publicboolIsRestore=false; privateStreamm_stream; privatelongm_position; privateTextReplaceRulesCollection_ReplaceRules; publicTextReplaceRulesCollectionReplaceRules { get
6、 { return_ReplaceRules; } set { _ReplaceRules=value; } } publicEncodingEncoding { get { return_Encoding; } set { _Encoding=value; } } p
7、rivateEncoding_Encoding=Encoding.UTF8; publicoverrideboolCanRead { get { returntrue; } } publicoverrideboolCanSeek { get { returnfalse; } } publicoverrideboolCanWrite {
8、 get { returnfalse; } } publicoverridelongLength { get
此文档下载收益归作者所有