public class CheckExeTime : IHttpModule
{
    public string ModuleName // Module Name Define
    {
        get { return "CheckTime"; }
    }

    private DateTime startTime;

    public void Init(HttpApplication application)  // IhttpModule 인터페이스 구현
    {
        application.BeginRequest += new EventHandler(application_BeginRequest);
        application.EndRequest += new EventHandler(application_EndRequest);
    }
    public void Dispose() // IhttpModule 인터페이스 구현
    {
    }
    public void application_BeginRequest(object source, EventArgs e)
    {
        startTime = DateTime.Now; // 요청 시간 Check
    }

    public void application_EndRequest(object source, EventArgs e)
    {
        //현재의 HttpApplication 개체를 얻어온다
        HttpApplication app = (HttpApplication)source;
        //현재 웹 어플리케이션의 컨텍스트를 얻어온다
        HttpContext context = app.Context;

        string pageID = context.Request.CurrentExecutionFilePath.ToString(); // 요청한 PageID (*.aspx)
        string requestIP = context.Request.UserHostAddress; // 요청한 Client IP

        TimeSpan span = DateTime.Now - startTime;

        // TO DO : 출력형식을 자유롭게 코딩하면 됨(텍스트파일로 쓰기 / DB에 저장)

        context.Response.Write("");
    }
}

위 소스를 작성한 후 아래 구문을 web.config에 추가하면 asp.net 페이지가 동작을 하면 실행이 된다.

[IIS 6.0 및 IIS 7.0 기본 모드에서 HTTP 모듈 등록]


    
        
    



[통합 모드의 IIS 7.0에서 HTTP 모듈 등록]

    
        
    

+ Recent posts