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信息安全团队
  • 相关阅读:
    PHP构造方法和析构函数
    数组的排序算法
    Swift---- 可选值类型(Optionals) 、 断言(Assertion) 、 集合 、 函数
    Swift----方法 、 下标 、 继承 、 初始化 、 析构方法 、 可选链
    Swift----函数 、 闭包 、 枚举 、 类和结构体 、 属性
    Swift-----类型转换 、 嵌套类型 、 扩展 、 协议 、 访问控制
    程序员创业-行业分析之区分易混淆的基本概念
    MSSQl分布式查询(转)
    iOS8中添加的extensions总结(一)——今日扩展
    Python Function Note
  • 原文地址:https://www.cnblogs.com/secbook/p/2654917.html
Copyright © 2011-2022 走看看