Click here to Skip to main content
11,641,209 members (62,505 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads
Add your own
alternative version

The Two Interceptors: HttpModule and HttpHandlers

, 4 Mar 2009 CPOL 235.2K 3K 255
The two interceptors: HttpModule and HttpHandlers
using System;
using System.Web;
using System.IO;
namespace MyPipeLine
    public class clsMyHandler  : IHttpHandler

        public void ProcessRequest(System.Web.HttpContext context)
            context.Response.Write("The page request is " + context.Request.RawUrl.ToString());
            StreamWriter sw = new StreamWriter(@"C:\requestLog.txt",true);
            sw.WriteLine("Page requested at " + DateTime.Now.ToString() + context.Request.RawUrl); sw.Close();
        public bool IsReusable
                return true;

    public class clsMyModule : IHttpModule
        public clsMyModule()
        public void Init(HttpApplication objApplication)
            // Register event handler of the piple line
            objApplication.BeginRequest += new EventHandler(this.context_BeginRequest);
            objApplication.EndRequest += new EventHandler(this.context_EndRequest);
        public void Dispose()

        public void context_EndRequest(object sender, EventArgs e)
            StreamWriter sw = new StreamWriter(@"C:\requestLog.txt",true);
            sw.WriteLine("End Request called at " + DateTime.Now.ToString()); sw.Close();
        public void context_BeginRequest(object sender, EventArgs e)
            StreamWriter sw = new StreamWriter(@"C:\requestLog.txt",true);
            sw.WriteLine("Begin request called at " + DateTime.Now.ToString()); sw.Close();

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Shivprasad koirala
India India

I am an ex-Microsoft MVP for ASP/ASP.NET and currently a CEO of a small
E-learning company in India. We are very much active in making training videos, writing books and corporate trainings. Do visit my site for 
.NET, C#, Design Pattern, WCF, Silverlight, LINQ, ASP.NET, ADO.NET, SharePoint, UML, SQL Server  training 
and Interview questions and answers

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150731.1 | Last Updated 4 Mar 2009
Article Copyright 2008 by Shivprasad koirala
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid