title: How to address all events in global.asax file when we work with ASP.NET Core Middleware
body: <p>here is the list of major events in global.asax file. suppose when we write code for each event in global.asax file to handle situation and when we will work with ASP.NET Core Middleware then tell me how to address each event code in ASP.NET Core Middleware. please come with a sample code to address all events in ASP.NET Core Middleware.</p>
  
  <p><strong>Application_Init:</strong> </p>
  
  <blockquote>
    <p>Fired when an application initializes or is first called. It is
    invoked for all HttpApplication object instances.</p>
  </blockquote>
  
  <p><strong>Application_Disposed:</strong> </p>
  
  <blockquote>
    <p>Fired just before an application is destroyed. This is the ideal
    location for cleaning up previously used resources.</p>
  </blockquote>
  
  <p><strong>Application_Error:</strong> </p>
  
  <blockquote>
    <p>Fired when an unhandled exception is encountered within the
    application.</p>
  </blockquote>
  
  <p><strong>Application_Start:</strong> </p>
  
  <blockquote>
    <p>Fired when the first instance of the HttpApplication class is created.
    It allows you to create objects that are accessible by all
    HttpApplication instances.</p>
  </blockquote>
  
  <p><strong>Application_End:</strong> </p>
  
  <blockquote>
    <p>Fired when the last instance of an HttpApplication class is destroyed.
    It is fired only once during an application's lifetime.</p>
  </blockquote>
  
  <p><strong>Application_BeginRequest:</strong> </p>
  
  <blockquote>
    <p>Fired when an application request is received. It is the first event
    fired for a request, which is often a page request (URL) that a user
    enters.</p>
  </blockquote>
  
  <p><strong>Application_EndRequest:</strong> </p>
  
  <blockquote>
    <p>The last event fired for an application request.</p>
  </blockquote>
  
  <p><strong>Application_PreRequestHandlerExecute:</strong> </p>
  
  <blockquote>
    <p>Fired before the ASP.NET page framework begins executing an event
    handler like a page or Web service.</p>
  </blockquote>
  
  <p><strong>Application_PostRequestHandlerExecute:</strong> </p>
  
  <blockquote>
    <p>Fired when the ASP.NET page framework has finished executing an event
    handler.</p>
  </blockquote>
  
  <p><strong>Applcation_PreSendRequestHeaders:</strong> </p>
  
  <blockquote>
    <p>Fired before the ASP.NET page framework sends HTTP headers to a
    requesting client (browser).</p>
  </blockquote>
  
  <p><strong>Application_PreSendContent:</strong> </p>
  
  <blockquote>
    <p>Fired before the ASP.NET page framework send content to a requesting
    client (browser).</p>
  </blockquote>
  
  <p><strong>Application_AcquireRequestState:</strong> </p>
  
  <blockquote>
    <p>Fired when the ASP.NET page framework gets the current state (Session
    state) related to the current request.</p>
  </blockquote>
  
  <p><strong>Application_ReleaseRequestState:</strong> </p>
  
  <blockquote>
    <p>Fired when the ASP.NET page framework completes execution of all event
    handlers. This results in all state modules to save their current
    state data.</p>
  </blockquote>
  
  <p><strong>Application_ResolveRequestCache:</strong> </p>
  
  <blockquote>
    <p>Fired when the ASP.NET page framework completes an authorization
    request. It allows caching modules to serve the request from the
    cache, thus bypassing handler execution.</p>
  </blockquote>
  
  <p><strong>Application_UpdateRequestCache:</strong> </p>
  
  <blockquote>
    <p>Fired when the ASP.NET page framework completes handler execution to
    allow caching modules to store responses to be used to handle
    subsequent requests.</p>
  </blockquote>
  
  <p><strong>Application_AuthenticateRequest:</strong> </p>
  
  <blockquote>
    <p>Fired when the security module has established the current user's
    identity as valid. At this point, the user's credentials have been
    validated.</p>
  </blockquote>
  
  <p><strong>Application_AuthorizeRequest:</strong> </p>
  
  <blockquote>
    <p>Fired when the security module has verified that a user can access
    resources.</p>
  </blockquote>
  
  <p><strong>Session_Start:</strong> </p>
  
  <blockquote>
    <p>Fired when a new user visits the application Web site.</p>
  </blockquote>
  
  <p><strong>Session_End:</strong> </p>
  
  <blockquote>
    <p>Fired when a user's session times out, ends, or they leave the
    application Web site.</p>
  </blockquote>
  
  <p>Thanks</p>