技术开发 频道

深入解读IIS 7中应用程序池的管道模式

  我为该模块实现简单的功能(将用户的请求地址打印出来在页面上)

using System;
using System.Web;

namespace WebApplication2
{
    
public class MyModule1 : IHttpModule
    {
        
/// <summary>
        
/// You will need to configure this module in the web.config file of your
        
/// web and register it with IIS before being able to use it. For more information
        
/// see the following link: http://go.microsoft.com/?linkid=8101007
        
/// </summary>
        
#region IHttpModule Members

        
public void Dispose()
        {
            
//clean-up code here.
        }

        
public void Init(HttpApplication context)
        {
            
// Below is an example of how you can handle LogRequest event and provide
            
// custom logging implementation for it
            context.LogRequest
+= new EventHandler(OnLogRequest);
        }

        #endregion

        
public void OnLogRequest(Object source, EventArgs e)
        {
            
//custom logging logic can go here
            var app
= (HttpApplication)source;
            app.Response.Write(app.Request.Url.ToString());
        }
    }
}

  3.注册该模块

  模块是需要注册才能够使用的。我们一般会想到以前的做法

<system.web>
    
<compilation debug="true" targetFramework="4.0" />
    
<httpModules>
      
<add name="test" type="WebApplication2.MyModule1,WebApplication2"/>
    
</httpModules>
  
</system.web>
0
相关文章