Asp. NET request processing mechanism preliminary exploration tour-Part 3 pipeline

Source: Internet
Author: User

1. Get to know HttpModule and httphandlersfirst.

They help us inject custom logic processing before and after the ASP. One is the system level (which can change the processing flow of the request) and the other is the business level.

If the logic you want to inject is based on an extension file like '. aspx ', '. html ', then you can use HttpHandler. In ASP. WebForm, both the generic handler and the webpage implement the IHttpHandler interface, and ASP. NET MVC also has Mvchandler implements the IHttpHandler interface

If you want to inject logic into an ASP. NET pipeline event, you can use HttpModule. For example, if ASP. NET implements the HttpModule for WebForm and MVC by default, UrlRoutingModule is used by default in ASP. This is done by overwriting the Global file or customizing a class that implements the IHttpModule interface and registering it in Web. config.

2.

A very valuable question is what can we do in the event? The following table shows the answer to this question:

Section Event Description
HttpModule BeginRequest This event marks a new request, which guarantees that it will be triggered in every request.
HttpModule AuthenticateRequest This event flags the ASP. NET runtime ready to authenticate the user. Any authentication code can be injected here.
HttpModule AuthorizeRequest This event flags the ASP. Runtime to prepare the authorized user. Any authorization code can be injected here.
HttpModule Resolverequest In ASP. We usually use the OutputCache directive to do the caching. In this event, ASP. The NET runtime determines whether the page can be loaded from the cache instead of being built from scratch. Any specific activity of the cache can be injected here.
HttpModule AcquireRequestState This event marks the time when the ASP . NET runtime is ready to get session variables. You can do whatever you want to do with the session variable.
HttpModule PreRequestHandlerExecute Occurs exactly before the event handler is started by ASP. You can pre-process what you want to do.
HttpHandler ProcessRequest HttpHandler logic is executed. In this section we will write the required logic for each page extension.
Page Init This event occurs on an ASP. NET page and can be used to:
1. Create controls dynamically, if you must create controls at run time;
2. Any initialization settings
3. Master pages and their settings
In this section we do not get viewstate, postedvalues, and already initialized controls.
Page Load In this section the ASP. NET control is fully loaded and here you can write UI operation logic or any other logic. Note: This event is also one of our most common and frequently used events.
Page Validate If you have a validator on the page, you also want to do a check here.
Page Render It's time to send the output to the browser. If you want to make some changes to the final HTML, you can enter your HTML logic here.
Page Unload The Page object is unloaded from memory.
HttpModule PostRequestHandlerExecute You can inject whatever logic you want after the handler executes.
HttpModule ReleaseRequestState If you want to save changes to certain state variables, for example: The value of the session variable.
HttpModule Updaterequestcache Before you finish, do you want to update your cache.
HttpModule EndRequest This is the last stage before the output is sent to the client browser.

Asp. NET request processing mechanism preliminary exploration tour-Part 3 pipeline

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.