zoukankan      html  css  js  c++  java
  • 浅谈Httpmodules

    HttpModule是ASP.NET过滤器,可以理解为HTTP请求的必经之地
    我们只要实现IHttpModule接口,就可以取代HttpModule

    namespace BookShop.Handler
    {
    public class TestModule : IHttpModule
    {
    /// <summary>
    /// 您将需要在网站的 Web.config 文件中配置此模块
    /// 并向 IIS 注册它,然后才能使用它。有关详细信息,
    /// 请参见下面的链接: http://go.microsoft.com/?linkid=8101007
    /// </summary>
    #region IHttpModule Members

    public void Dispose()
    {
    //此处放置清除代码。
    }

    public void Init(HttpApplication context)
    {
    // 下面是如何处理 LogRequest 事件并为其
    // 提供自定义日志记录实现的示例
    context.LogRequest += new EventHandler(OnLogRequest);
    context.BeginRequest += Context_BeginRequest;
    context.EndRequest += Context_EndRequest;
    }

    private void Context_EndRequest(object sender, EventArgs e)
    {
    HttpApplication app = sender as HttpApplication;
    app.Context.Response.Write("执行了HttpMoudle的endRequest事件");
    }

    private void Context_BeginRequest(object sender, EventArgs e)
    {
    HttpApplication app = sender as HttpApplication;
    app.Context.Response.Write("执行了HttpMoudle的BeginRequest事件");

    }

    #endregion

    public void OnLogRequest(Object source, EventArgs e)
    {
    HttpApplication app = source as HttpApplication;
    app.Context.Response.Write("执行了HttpMoudle的LogRequest事件");
    }
    }
    }


    web.config
    <httpModules>
    <add name="myHttpModule" type="ClassLibrary1.MyHttpModule,ClassLibrary1"/>
    </httpModules>

  • 相关阅读:
    Codeforces Round #260 (Div. 1) A
    cdoj 1131 男神的礼物 区间dp
    bzoj2435: [Noi2011]道路修建 树上dp
    hdu 4597 Play Game 区间dp
    cdoj 31 饭卡(card) 01背包
    hdu5256 序列变换 dp LIS
    BZOJ 4027: [HEOI2015]兔子与樱花 树上dp
    Codeforces Round #202 (Div. 1) D. Turtles dp
    hdu 4114 Disney's FastPass 状压dp
    Python help() 函数
  • 原文地址:https://www.cnblogs.com/ZaraNet/p/9433533.html
Copyright © 2011-2022 走看看