zoukankan      html  css  js  c++  java
  • HTTPFilter 的例子

    using System;
    using System.Web;
    using System.Diagnostics;


    namespace HDI
    {
      public class HTTPFilter : IHttpModule
      {

        System.IO.StreamWriter fileWriter;
        HttpApplication applicationContext;
        EventHandler beginRequestEventHandler;
        String fileName;

        public void Init(HttpApplication context)
        {
          //Store file name for later use.
          fileName = context.Context.Request.PhysicalApplicationPath + "HTTPFilter.txt";

          //Open file and write information.
          fileWriter = new System.IO.StreamWriter(fileName, true);
          fileWriter.WriteLine(System.DateTime.Now.ToString("MM.dd.yyyy HH:mm:ss:ffffff"));
          fileWriter.WriteLine("Init");
          fileWriter.Flush();
          fileWriter.Close();

          context.Error += (new EventHandler(this.Application_err));

                 


          //Store for access in other events.
          applicationContext = context;
          beginRequestEventHandler = new System.EventHandler(this.OnBeginRequest);
          applicationContext.BeginRequest += beginRequestEventHandler;
        }

        public void Dispose()
        {

          //Open file and write information.
          fileWriter = new System.IO.StreamWriter(fileName, true);
          fileWriter.WriteLine(System.DateTime.Now.ToString("MM.dd.yyyy HH:mm:ss:ffffff"));
          fileWriter.WriteLine("Dispose");
          fileWriter.Flush();
          fileWriter.Close();

          //Clean-up.
          applicationContext.BeginRequest -= beginRequestEventHandler;
          beginRequestEventHandler = null;
        }

          protected void OnBeginRequest(object sender, EventArgs e)
          {
              //Open file and write information.
              fileWriter = new System.IO.StreamWriter(fileName, true);
              fileWriter.WriteLine(System.DateTime.Now.ToString("MM.dd.yyyy HH:mm:ss:ffffff"));
              fileWriter.WriteLine("OnBeginRequest");
              fileWriter.WriteLine(applicationContext.Context.Request.UserAgent);
              fileWriter.WriteLine(applicationContext.Context.Request.UserHostAddress);
              fileWriter.WriteLine(applicationContext.Context.Request.Url.ToString());
              fileWriter.Flush();
              fileWriter.Close();
          }

          protected void Application_err(object sender, EventArgs e)
          {
              //Open file and write information.
              fileWriter = new System.IO.StreamWriter(fileName, true);
              fileWriter.WriteLine(System.DateTime.Now.ToString("MM.dd.yyyy HH:mm:ss:ffffff"));
              fileWriter.WriteLine( applicationContext.Context.Error.Message+applicationContext.Context.AllErrors.ToString());

    //Context.Server.GetLastError()
              fileWriter.Flush();
              fileWriter.Close();
          }

      }
    }

    关于作者: 王昕(QQ:475660) 在广州工作生活30余年。十多年开发经验,在Java、即时通讯、NoSQL、BPM、大数据等领域较有经验。
    目前维护的开源产品:https://gitee.com/475660
  • 相关阅读:
    MySQL内连接和外连接
    MySQL 重命名数据库
    linux查看文件大小
    Linux合并两个文件夹内容
    Linux压缩和解压命令
    深度学习反向求导
    深度学习网络压缩模型方法总结
    cuda培训素材
    cuda编程-卷积优化
    交叉熵代价函数(损失函数)及其求导推导
  • 原文地址:https://www.cnblogs.com/starcrm/p/1344955.html
Copyright © 2011-2022 走看看