asp.net 生成静态页面

2012/11/28 15:44
阅读数 65
 
先写一个类:
public class ResponseFilter : Stream
    {
        private Stream m_sink;
        private long m_position;
        private FileStream fs;
        public ResponseFilter(Stream sink)
        {
            m_sink = sink;
            fs = new FileStream(@"C:\FilterOutput\Products.htm", FileMode.OpenOrCreate, FileAccess.Write);
        }
        // The following members of Stream must be overriden.
        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 m_position; }
            set { m_position = value; }
        }
        public override long Seek(long offset, System.IO.SeekOrigin direction)
        {
            return 0;
        }
        public override void SetLength(long length)
        {
            m_sink.SetLength(length);
        }
        public override void Close()
        {
            m_sink.Close();
            fs.Close();
        }
        public override void Flush()
        {
            m_sink.Flush();
        }
        public override int Read(byte[] buffer, int offset, int count)
        {
            return m_sink.Read(buffer, offset, count);
        }
        // Override the Write method to filter Response to a file.
        public override void Write(byte[] buffer, int offset, int count)
        {
            //Write out the response to the browser.
            m_sink.Write(buffer, 0, count);
            //Write out the response to the file.
            fs.Write(buffer, 0, count);
        }
    }
 //把类调用到OnInit方法中
        #region OnInit
        /// <summary>
        /// 生成静态页
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit(EventArgs e)
        {
           Response.Filter = new ResponseFilter(Response.Filter);
        }
        #endregion
 
 
来源于:www.hackbadboy.com   BadBoy网络安全小组  B.B.S.T信息安全团队

原文链接: http://blog.csdn.net/mypc2010/article/details/7048494
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部