Thoughts on ASP. NET context path and httpmodule and httphandler

Source: Internet
Author: User
1. obtain common attributes of the access path in the Asp.net context:

? Context. Request. physicalapplicationpath
"E:" "xumh" "eductaction" "webform08" "asp_net_http """

? Context. Request. physicalpath
"E:" "xumh" "eductaction" "webform08" "asp_net_http" "Images" "bookcovers" "9787115152572.jpg"

? Context. Request. rawurl
"/Images/bookcovers/9787115152572.jpg"

? Context. Request. url. absolutepath
"/Images/bookcovers/9787115152572.jpg"

? Context. Request. url. absoluteuri
& Quot; http: // localhost: 1103/images/bookcovers/9787115152572.jpg& quot"

? Context. Request. Path
"/Images/bookcovers/9787115152572.jpg"

? Context. Request. filepath
"/Images/bookcovers/9787115152572.jpg"

2. Thinking about httpmodule and httphandler:

Asp. when the HTTP request is processed by net, the requests are processed by each httpmodule in the pipeline (pipeline) mode and then to httphandler. After the httphandler completes processing, the requests are still processed by each httpmodule in the pipeline, finally, the HTML is sent to the client browser.
??? The ASP. NET system is configured with many httphandler and httpmodule to process. Net standard page files such as aspx and standard event processing in these page files. View the httphandlers and httpmodules nodes in the web. config file under the % System %/Microsoft. NET "Framework" v2.0.50727 "Config directory. If you are interested, you can use reflector to view related classes and methods in the. NET System and learn how. Net handles and what it does. Net also provides a mechanism to develop custom httphandler and httpmodule, which can be used to intercept httprequest and complete custom processing.

httpmodule
inherits the system. Web. ihttpmodule interface and implements its own httpmodule class. Two methods must be implemented: init and dispose. In init, you can add events to be intercepted. Dispose is used to release resources. If you have created your own resource objects in init, release them in dispose.
copy the compiled DLL file to the bin directory of the web project. config file system. web node configuration:



in this way, the custom httpmodule class myhttpmodule is inserted into the pipeline of the current web httpmodule.
the main function of httpmodule is to intercept all application events and complete processing of these events. In fact, if you develop some projects by yourself, it is enough to directly process them in global. asax. If you are developing a framework or some components, you need to add processing to the event and develop a custom httpmodule. You can avoid using the framework or components manually at Global. add Code to asax.
currently, the intended use of custom httpmodule development is as follows, provides global identity/permission verification, custom Website access/operation log records, and monitors and tracks websites for management and debugging purposes. Of course, if the framework is developed with a custom httphandler, httpmodule can be used for some other special processing.

Httphandler
Httphandler completely intercepts HTTP requests.
First, inherit the system. Web. ihttphandler interface to implement your own httphandler class. The processrequest method and isreusable attribute of the interface must be implemented. The processrequest method processes each HTTP request and sends the HTML of the processing result to the output cache. The isreusable attribute is called by the. NET Framework to determine whether the httphandler instance can be reused for other requests of the same type.
If you need to read or write the session value in your httphandler class, you need to inherit an irequiressessionstate interface. This interface does not have any method, but is only a tag interface. After inheriting this interface, you can access the session in your httphandler and write the value in the session.

For specific examples, seeMy blogAll examples are original and can be run directly.

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.