IHttpModule接口用于处理Web请求之前的准备工作,如权取验证等
可以根据需要在程序中编写多个实现IHttpModule接口的模块,在Web.config中进行装/卸载,从而实现功能的添加和删减,不用改动其它部分
在Web.config的<System.Web>节中添加如下配置节
<httpModules>
<add name="yourHpptModulesName" type="ClassName"/>//都用类名即可
</httpModules>
其中yourHttpModulesName类必须实现IHttpModule接口这个功能就是在Web请求处理之前调用这个模块的方法Init
如果不不此功能,在Web.config中注释掉即可

解决方案 »

  1.   

    public class ModuleDemo:IHttpModule
    {
        public void Init(HttpApplication context) {
           context.BeginRequest += new EventHandler(context_BeginRequest);
           context.EndRequest += new EventHandler(context_EndRequest);
        }
        void context_BeginRequest(object sender, EventArgs e) {
           HttpApplication application = (HttpApplication)sender;
           HttpContext context = application.Context;
           string uri = context.Request.Url.AbsolutePath.ToLower();    }
        void context_EndRequest(object sender, EventArgs e) {
           HttpApplication application = (HttpApplication)sender;
           HttpContext context = application.Context;
         
        }
           
        public void Dispose() {
        }
    }
    <system.web>
        <httpModules>
           <add name="MyModule" type="ModuleDemo" />
        </httpModules>
    </system.web>SP.NET 把http请求依次传递给管道中各个HttpModule,最终被HttpHandler处理,处理完成后,再次经过管道中的HTTP模块,把结果返回给客户端
      

  2.   

    module 可以监听所有请求handler 只可服务一次请求.
      

  3.   

    配置没有问题,但是这种做法,对asp页面的请求确实是不响应的
      测试中在 
    m_application.BeginRequest += new EventHandler(CheckUrl_BeginRequest);插入断点 在站点下随便放一个xxx.asp文件 xxx.html文件 xxx.aspx文件 xxx.js文件可以什么都不写
    分别访问以下页面
    只有request是XXX.asp文件时不经过断点.
      

  4.   

    奇怪的就是asp只有页面不会触发Init()方法具体可以看我在4楼的描述
      

  5.   

    看iis的配置,默认情况下,asp是使用另外的处理模块处理的。
      

  6.   

    刚看了一下
    ---------------------------------------------
    IIS 的Web 服务扩展 - Active Server Pages
    现在选择的程序是
    C:\WINDOWS\system32\inetsrv\asp.dll
    ---------------------------------------------
    Web 服务扩展 - ASP.NET v2.0.50727
    选择的程序是
    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
    ---------------------------------------------
    好像不能选择 请教各位如何修改iis配置才能使asp页面的请求也受继承自IHttpModule类的响应,谢谢了
      

  7.   

    暂时没有开发asp  顶一下吧