title: How can I execute common code for every request?
body: <p>Is there any possibility to find function like <code>Page_Load</code>? I have MVC application and I need run some code every page is loaded, or reloaded, or I call some controller. One shared function for everything classes?</p>
  
  <p>I try Application_Start, but this execute only for first time application run. I search some like <code>BeginRequest</code>, but this function have been call several times, I need only first, when I load page and I need end function, like constructor and destructor for whole project.</p>
  
  <p>Here is sample code.</p>
  
  <pre><code>public class MvcApplication : System.Web.HttpApplication
  {
      protected void Application_Start()
      {
          AreaRegistration.RegisterAllAreas();
          FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
          RouteConfig.RegisterRoutes(RouteTable.Routes);
      }  
  }
  </code></pre>
  
  <p><code>document.ready</code> isn't my case. And call function every controller is last option. The code must be executed before any other function have been called. And before all end, i need run end function. For example, at first I need created mysql connector shared for all classes. And at end I need close mysql connection.</p>