zoukankan      html  css  js  c++  java
  • asp.net 生成静态页面

     
    先写一个类:
    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信息安全团队
  • 相关阅读:
    清除大文本中的html标签
    页面中富文本的使用
    artDialog的几种基本使用
    SQL基础-->层次化查询(START BY ... CONNECT BY PRIOR)[转]
    Struts2
    js中window.location的用法
    keycode键盘 按键
    jQuery升级踩坑之路
    生成唯一随机码的方法及优缺点分析
    百度API的经历,怎样为多个点添加带检索功能的信息窗口
  • 原文地址:https://www.cnblogs.com/secbook/p/2654917.html
Copyright © 2011-2022 走看看