Using HTTP modules to extend ASP.net processing

Source: Internet
Author: User
Tags extend header web services

An HTTP module is an assembly that is invoked each time a request is made against an application by implementing the IHttpModule interface and handling the event. HTTP modules are invoked as part of the ASP.net request pipeline to access life cycle events throughout the request process. Therefore, the HTTP module gives us the opportunity to check incoming and outgoing requests and take action based on that request. Even we can participate in the management of ASP.net operations by implementing HTTP modules, for example, ASP.net provides sessionstatemodule to provide session-state services to applications.

Well, before using the HTTP module, let's review the lifecycle event for one request:

Here, specifically, HTTP modules are different from HTTP handlers. HTTP modules can be invoked for all requests and responses, and HTTP handlers run only in response to a specific request.

Typical uses of HTTP modules include:

L Security. Because you can check incoming requests, HTTP modules can perform custom authentication or other security checks before requesting a page, an XML Web services, or calling a handler.

L Statistical information and log records. Because HTTP modules are invoked on each request, you can collect request statistics and logging information into a single set of modules instead of being collected in each page.

L A custom header or footer. Because you can modify the outbound response, you can inject content, such as custom header information, into every page or XML Web services response.

The ASP.net HTTP module runs against all requests, similar to the ISAPI filter. However, they are written in managed code and can be fully integrated with the lifecycle of the ASP.net application. The general process for writing asp.net HttpModule is:

L Implement IHttpModule interface.

L HANDLE the Init method and register for the required events.

L HANDLE the event.

L You can also implement the Dispose method if you need to clean it.

L REGISTER the module in Web.config.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.