title: Application_BeginRequest not firing for cached results?
body: <p>I`m writing an ASP.NET MVC application using IIS 7.5 as web server.
  I would like to open a DB connection at the begin of any request and close this connection at the end of the request.</p>
  
  <p>Therefore, in global.asax I specify the member</p>
  
  <pre><code>Public Shared conn As OleDbConnection
  </code></pre>
  
  <p>In the Application_BeginRequest handler I open the connection like this:</p>
  
  <pre><code>Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
     Dim strConn As String = "myConnectionString..."
     conn = New OleDbConnection(strConn)
     conn.Open()
  End Sub 'Application_BeginRequest
  </code></pre>
  
  <p>And in the Application_EndRequest handler I close it:</p>
  
  <pre><code>Sub Application_EndRequest(ByVal sender As Object, ByVal e As EventArgs)
     conn.Close()
     conn.Dispose()
  End Sub 'Application_EndRequest
  </code></pre>
  
  <p>Then, maybe in the Index() method of the HomeController, I use the Db connection provided by the global.asax:</p>
  
  <pre><code>Dim _conn As OleDbConnection = MvcApplication.conn
  '[then get or set data in the DB...]
  </code></pre>
  
  <p>I now experience a strange thing: The DB connection is opened properly when I completely reload a page from the server. When IIS delivers the page from cache, the DB connection is not openend and I get an error (although seemingly from my reporting tool the Application_BeginRequest handler IS entered). Is there a way to overcome this problem? I already tried setting the cache control via HTML metatags and by leveraging the following Q&amp;A provided here: <a href="https://stackoverflow.com/questions/4078011/how-to-switch-off-caching-for-mvc-requests-but-not-for-static-files-in-iis7">How to switch off caching for MVC requests but not for static files in IIS7?</a>
  The problem still remains. Can anyone help?
  Many thanks,
  niewi</p>