zoukankan      html  css  js  c++  java
  • IHttpModule

    随便写一个类继承IHttpModule

    实现IHttpModule中的两个方法 

    Init()

    Dispose()

            public void Init(HttpApplication context)
            {
                //throw new NotImplementedException();
                //恰好在 ASP.NET 开始执行事件处理程序(例如,某页或某个 XML Web services)前发生。
                context.PreRequestHandlerExecute += new EventHandler(Context_PreRequestHandlerExecute);
                //在 ASP.NET 事件处理程序(例如,某页或某个 XML Web service)执行完毕时发生。
                context.PostRequestHandlerExecute += new EventHandler(Context_PostRequestHandlerExecute);
    
            }
            //在 ASP.NET 事件处理程序(例如,某页或某个 XML Web service)执行完毕时发生。
            //页面加载完成后触发
            private void Context_PostRequestHandlerExecute(object sender, EventArgs e)
            {
                //throw new NotImplementedException();
            }
            //恰好在 ASP.NET 开始执行事件处理程序(例如,某页或某个 XML Web services)前发生。
            //页面加载前触发
            private void Context_PreRequestHandlerExecute(object sender, EventArgs e)
            {
                //获取到当前请求上下文
                HttpContext context = ((HttpApplication)sender).Context;
                var request = context.Request;
                //浏览器
                string browser = request.Browser.Browser;
                if (string.IsNullOrEmpty(browser))
                {
                    browser = "/home/index";
                }
                //绝对路径
                string url = request.Url.AbsolutePath;
                string host = request.Url.Host;
    
    
    
    
    
            }

    然后还需要到配置文件中配置一下

    在<system.webServer>这个节点下

        <modules runAllManagedModulesForAllRequests="true" >
          <add name="HttpModule111" type="MVCWebCount.Common.HttpModule111" />
        </modules>

    或者

        <modules runAllManagedModulesForAllRequests="true" >
          <add name="HttpModule111" type="MVCWebCount.Common.HttpModule111,MVCWebCount" />
        </modules>

    name就是自己随便写的那个类

    type是这个类所在的地址,后半截是他所在的程序集

  • 相关阅读:
    CacheHelper
    自动完成 或者动态匹配
    http://www.jb51.net/article/28619.htm
    http://www.kindsoft.net/docs/qna.html
    开发测试的理想模型
    关于浮点数的死区问题
    ZOJ Problem Set – 2321 Filling Out the Team
    Input类、四元数、
    忙蒙蔽了
    2014-03-28
  • 原文地址:https://www.cnblogs.com/ansheng/p/5486474.html
Copyright © 2011-2022 走看看