输出过滤 Asp.net Response.Filter

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO ; using System.Text.RegularExpressions; namespace BasicCompent {     public   class PageResponseFilter:Stream     {         private Stream mSink;         private long mPosition;         Encoding responseCoding;         public PageResponseFilter(Stream sink, Encoding coding)         {             mSink = sink;             responseCoding = coding;         }         public override bool CanRead         {             get { return true; }         }         public override bool CanSeek         {             get { return false; }         }         public override bool CanWrite         {             get { return false; }         }         public override long Length         {             get { return 0; }         }         public override long Position         {             get             {                 return mPosition;             }             set             {                 mPosition = value;             }         }         public override long Seek(long offset, SeekOrigin origin)         {             return 0;         }         public override void SetLength(long value)         {             mSink.SetLength(value);         }         public override void Close()         {             mSink.Close();         }         public override void Flush()         {             mSink.Flush();         }         public override int Read(byte[] buffer, int offset, int count)         {             return mSink.Read(buffer, offset, count);         }         public override void Write(byte[] buffer, int offset, int count)         {             string pubString = responseCoding.GetString(buffer, offset, count);             int fIndx = pubString.IndexOf("<body>", 0, StringComparison.OrdinalIgnoreCase);             if (fIndx != -1)             {                 pubString = pubString.Insert(fIndx + 6, "<!---------测试用的---------//>");             }             byte[] res = responseCoding.GetBytes(pubString);             mSink.Write(res, 0, res.Length);         }     } }

posted on 2008-07-08 11:17  老代哥哥  阅读(192)  评论(0编辑  收藏  举报

导航