Http Modules allow you to extend the existing ASP.NET pipeline. The most common use of HTTPModules is pre and/ore postprecessing of requests. Internally ASP.NET utilizes custom modules (httpmodules) for: output caching, authentication and authorization etc. Therefore, if you ever need to tap into the pipleline to alter the request in any way, look into HttpModules as they provide a relatively easy way for you to do just that (similiar to how ISAPI filters helped achieve pre/post processing capabilities).
To develop an HttpModule you are required to do the following:
- You class must implement the iHttpModule Interface
- Both the Init(..) and Dispose() methods must be in your class definitions
Below is a simple example that outputs "HttpModule says Hello!" to each and every request. You will notice that I wired an event in the Init(..) method that calls OnBeginRequest at the beginning of every request.
|
In your web.config, add the following elements:<httpModules><add type="CSharpFriends.Samples.CSharpFriendsHttpModule,Test" name="CSharpFriendsHttpModule" /></httpModules>