What is httpmodule?

Source: Internet
Author: User

When learning dnn to urlrewritemodule class (in urlrewritemodule. VB), we found that this class was inherited by the ihttpmodule interface. According to msdn, urlrewritemodule was originally an httpmodule. So what is httpmodule? What is the purpose? What are the benefits of using it?
I have never used httpmodule before (I can see how different my knowledge is from the huge function of. net ). This study of dnn gave me the opportunity to see httpmodule, so I cannot leave this knowledge point blank. After querying the relevant information, I finally got a preliminary understanding of httpmodule.
Httpmodule implements the ihttpmodule interface and handles events.ProgramSet. ASP. NET contains a group of httpmodule modules that can be used by applications. For example, ASP. NET provides sessionstatemodule to provide session status services to applications. You can create custom httpmodule to respond to ASP. NET events or user events.
The general process of compiling httpmodule is:
1. Implement the ihttpmodule interface, for example:

Public class urlrewritemoduleclass urlrewritemodule
Implements ihttpmodule
End Class

2. Handle the init method and register the required event, for example:

Public sub Init () sub Init (byval application as httpapplication) implements ihttpmodule. init
'Register the event handler onininrequest for the httpapplication event beginrequest upon initialization.
Addhandler application. beginrequest, addressof me. onbeginrequest
End sub

3. process the event, such:

Public sub onbeginrequest () sub onbeginrequest (byval s as object, byval e as eventargs)
'CodeOmitted
End sub

4. If necessary, you can implement the dispose method as needed.

Public sub dispose () implements ihttpmodule. Dispose
End sub

5. Register this module in Web. config.

<! -- Configure the HTTP module in an application -->
<Httpmodules>
<Add name = "urlrewrite" type = "dotnetnuke. httpmodules. urlrewritemodule, dotnetnuke. httpmodules. urlrewrite"/>
</Httpmodules>

In the original application. the beginrequest event (triggered when a new request is sent) is generally written in global. in application_beginrequest in asax, there are not many beginrequest events in the original program, and the amount of code is very small. The code for processing the beginrequest event is put into global. there is no problem in asax. However, in dnn, there are many beginrequest events to be processed, and there may be expansion requirements. Besides, writing event processing of different functions to different httpmodules can also make the code structure clearer.
But if multiple httpmodules contain application. beginrequest, what is the execution sequence of the program? Are you sure you want to execute in global. asax first and then follow the order in Web. config? No answer has been found for this. Please let me know. Thank you! What are the more benefits of using httpmodule? I hope you can point it out. Thank you again!

Related Knowledge:
Http://msdn.microsoft.com/library/chs/default.asp? Url =/library/CHS/cpguide/html/cpconhandlingpublicevents. asp

Implement URL rewriting in ASP. NET

More>

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.