In This Chapter:
This chapter teaches you how to write custom server controls and how to add content to pages automatically using HttpModules. The sample application that we will build is a server control that tracks feedback about specific ASP.NET pages. Rather then adding this control to each page that we want to track, we will build an HttpModule that automatically places the control on every page within an application. This way, we can add or remove the feedback tracking control from every page by changing only a couple of lines in the web.config file.
HttpModules allow you to handle events generated by the HttpApplication class in a global manner. HttpModules are similar to ISAPI filters but are much easier to design and implement. With an HttpModule, you can do processing on a request at various stages of the request. Because an HttpModule is a global object, it is used to do things that affect most if not all of the .aspx files in your application. Here is a partial list of things that can be done with an HttpModule:
An HttpModule has two basic purposes. It provides event handlers for events generated by the Application object, and it can generate events that can be handled by your Global.asax file or the code file behind the Global.asax file. Both of these purposes will be discussed in detail.