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>

  • 相关阅读:
    hdu1430 魔板(康拓展开 bfs预处理)
    网络流EdmondsKarp算法模板理解
    poj3020 建信号塔(匈牙利算法 最小覆盖边集)
    bzoj 2465 小球
    bzoj 1822 冷冻波
    bzoj 1040 骑士
    Codeforces Round #460 (Div. 2)
    bzoj 1072 排列perm
    Codeforces Round #459 (Div. 2)
    bzoj 1087 互不侵犯King
  • 原文地址:https://www.cnblogs.com/ZaraNet/p/9433533.html
Copyright © 2011-2022 走看看