HTTP modules isProgramSet. It is called for every request of the program. HTTP modules is part of the Asp.net request pipeline and can access events throughout the request lifecycle. therefore, HTTP modules gives you an opportunity to check arrival requests and take actions. they also provide the opportunity to check external requests and modify requests.
Asp.net HTTP modules is similar to the ISAPI filter, and they can all get requests. However, they are managedCodeWritten and fully integrated in the lifecycle of the Asp.net program.
Typical HTTP modules usage
Security: Because you can detect incoming requests, your HTTP modules can perform custom authentication or other security checks on the request page, Web Service, or before calling handler.
Statistics and logs: Since HTTP modules is called before each request, you can obtain request statistics and log information from a centralized component instead of a separate page.
Custom header or footer: Because you can modify external requests, You can inject custom header information to each page or web service request.
Asp.net uses components (modules) to implement various program features, including forms authentication, caching, session Status and client script services. in each case, when these services are available, the component is called as part of the request and executes tasks other than a single page. components can cause program events to disappear or create those that can be stored in global. events initiated in ASX.
Note: HTTP modules and HTTP handlers are different. Http modules is called in all requests and responses, while HTTP hanlders is called only in corresponding and specific requests.
How does HTTP modules work?
In the web. register a custom HTTP modules in the config file. when Asp.net creates an httpapplication class instance to describe your program, any registered modules are also created. when a modules is created, its init method is called and the modules is initialized by itself.
In the init method of modules, You can bind events to the method to subscribe to various program events, such as beginrequest or endrequest. when an event is initiated, the methods in modules are called and can be processed in any logic, such as identity authentication or login information. during event processing, modules can read the context property of the current request. this allows you to redirect the request to another page, modify the request or implement any other processing. for example, if your modules includes authentication, modules can detect and redirect to the login page or error page. when the modules event processing is complete, Asp.net calls the next process in the pipeline, which may implement other modules or HTTP handler.
Use http modules? Or use global. asax?
You can use global. the asax file implements the function of a module, which can correspond to program events. however, modules is used instead of global. asax has an advantage that it can be compressed and created once and run in many programs. by adding them to the GAC and in the machine. config, You can reuse them in all programs.
However, using global. the advantage of asax is that you can replace the code in other module registration events, such as session_start and session_end. in addition, global. asax is your global object available throughout the program.
When you need to create code for dependency program events and you want to reuse module in other programs or do not want to replace complex code in global. asax, you should use module.
You should be in global. acax replacement code when you need to create code for dependent program events and you do not need to reuse it in other programs or you need to subscribe to events such as session_start (in modules, it cannot be subscribed ).
Reference: http://msdn2.microsoft.com/en-us/library/ms178468.aspx