This video provides an overview of the HTTPApplication processing pipeline, and examines the life-cycle events raised during request processing.
- [Instructor] Earlier in the course, we explored application-level events and the role of the HttpApplication class. Well, now, we take a closer look at the HttpApplication processing pipeline and the life cycle events that happen for every request. It's useful to know how a request is processed, so you can run code when key events get raised. The HttpApplication class has over 20 available events that you can subscribe to.
They handle a request at different stages of its processing. Let's look at the flow from a high level. First, the request goes through security and caching processes until it's assigned to an HTTP handler. After the handler finishes processing the request, it goes through more re-caching and logging events. Finally, the response gets sent back to the client. Keep in mind that HttpApplication instances are created by the ASP.NET infrastructure, and they process one request at a time.
And remember that all ASP.NET applications, whether they're web forms or MVC, share the same HttpApplication processing pipeline. Let's examine request events in more detail. We'll navigate to the .NET API documentation for HttpApplication. You'll find the link at the bottom of your screen. Let's scroll through to the section about application events under Remarks.
Here, you'll find the order of each event that's fired during events processing. BeginRequest gets raised first for every request that's processed. The next four events authenticate requests and authorize requests have to do with ASP.NET security processes that verify the identity of the user and make sure they're authorized. ResolveRequestCache lets the caching module serve the request from the cache.
And PostResolveRequestCache gets raised when that process is done. Next is MapRequestHandler, which is a pretty important event. This is where ASP.NET maps the current request to the appropriate handler. The PostMapRequestHandler event happens after that mapping is complete. The AcquireRequestState events involve getting the current state, like session state.
The RequestHandlerExecute Pre and Post events are raised before and after an HTTP handler executes the request. Once all request handlers are finished executing, the ReleaseRequestState events get raised. At this point, the application is done with the request, and ASP.NET saves the current state data. The caching modules are involved again in these next two events, UpdateRequestCache and PostUpdateRequestCache, this time to store the response for future use.
The LogRequest events are raised when ASP.NET performs logging of the current request. You could implement custom logging by handling this event. And finally, we have the last event of the HTTP pipeline and request. That was quite a bit of information, but it helps you understand what's involved in HTTP request processing. By handling any of these life cycle events, you can add custom logic for every request at the appropriate stage.
- Fundamentals of the request life cycle
- Designing and implementing HTTP modules and handlers
- Choosing between handlers and modules
- Understanding route handlers
- Configuring convention-based routing
- ASP.NET MVC attribute routing
- Creating a custom controller factory
- Defining a custom dependency resolver
- Creating a custom view engine