We'll create a new HTTP module, and track the starting/ending point of the request. We will also add information to the beginning of the response and end of the response.
- First, let's see the anatomy of an HTTP module:
public class MyHttpModule : IHttpModule { public void Dispose(){} public void Init(HttpApplication context) { context.BeginRequest += (source, args) => { context.Response.Write("MyHttpModule BeginRequest"); }; context.EndRequest += (source, args) => { context.Response.Write("MyHttpModule EndRequest"); }; } }
HttpModule has to be configured in the Web.config file as follows:
<system.webServer> <modules> <add name="myModule" type="MyApp.HttpModules.MyHttpModule"/> </modules> </system.webServer>
- Now, let's ...