Request Life Cycle Events in MVC

facebooktwittergoogle_plusredditpinterestlinkedinmail

In this blog, I want to discuss the request life cycle events and the importance of each event in a ASP.NET MVC application. The following requests are fired every time a request is made.

  • BeginRequest
  • The first event in the HTTP pipeline chain of execution when ASP.NET responds to a request

  • AuthenticateRequest
  • The AuthenticateRequest event ensures that the request will be authenticated before processing the attached module or event handler.

  • AuthorizeRequest
  • The AuthorizeRequest event ensures that the request will be authenticated and authorized before processing the attached module or event handler.

  • ResolveRequestCache
  • This event determines if a page can be served from the Output cache. If you want to write your own caching module (for example, build a file-based cache rather than a memory cache), synchronize this event to determine whether to serve the page from the cache.

  • MapRequestHandler
  • The MapRequestHandler is introduced in the .NET Framework version 3.5.The event is used by the ASP.NET infrastructure to determine the request handler for the current request. But some versions of IIS do not support this event.

  • AcquireRequestState
  • This event occurs when ASP.NET acquires the current state for example, retrieve Session state from the state store.

  • RequestHandlerExecute
      PreRequestHandlerExecute Event : This event occurs before the HTTP handler is executed.
      PostRequestHandlerExecute: This event occurs after the HTTP handler is executed.

    In between these two events MVC generates response.

  • ReleaseRequestState
  • This event occurs after ASP.NET finishes executing all request event handlers. This event causes state modules to save the current state data.Session state is stored back in the state store.

  • UpdateRequestCache
    This event writes output back to the Output cache.
  • LogRequest
    This event occurs just before ASP.NET performs any logging for the current request.
  • EndRequest
    This event occurs as the last event in the HTTP pipeline chain of execution when ASP.NET responds to a request.

You might also like:

The following two tabs change content below.

Tom Mohan

Tom Mohan is a technologist who loves to code and build. He enjoys working on Microsoft Technologies. Tom specializes in ASP.NET MVC, Web API , Azure, C# ,WPF, SQL etc and holds a Bachelor engineering degree in Computer Science. Certification : MCSD , MCTS