title: ASP.NET MVC doesn't call global.asax' EndRequest
body: <p>I am trying to perform some actions at the end of every request.
  I changed the Application_Start() that is generated when created new project to make a test:</p>
  
  <pre><code>protected void Application_Start()
  {
      EndRequest += (s, e) =&gt;
      {
          Console.Write("fghfgh");
      };
      RegisterRoutes(RouteTable.Routes);
  }
  </code></pre>
  
  <p>The lambda won't get called. Any ideas why?</p>
  
  <p>edit:
  I see that they are doing similar thing in SharpArch [<a href="http://code.google.com/p/sharp-architecture/]" rel="noreferrer">http://code.google.com/p/sharp-architecture/]</a> and it does work there...
  And no, I don't want to use an HttpModule.</p>
  
  <p>edit2:
  The only workaround I found is to use Application_EndRequest in conjuction with a private static member of global.asax:</p>
  
  <pre><code>private static WebSessionStorage wss;
  protected void Application_Start()
  {
      //...
      wss = new WebSessionStorage(this);
      //...
  }
  
  protected void Application_EndRequest(object sender, EventArgs e)
  {
      wss.EndRequest(sender, e);
  }
  </code></pre>
  
  <p>wss must be private because it seems like the Application_EndRequest is being called using different instance object (this). That may also be reason of my event (as described at the beginning) not being called.</p>