title: In ASP.NET MVC 3, How can I use OnResultExecuting/OnresultExecuted method to trace the page load time?
body: <p>I put OnResultExecuting/OnResultExecuted code in my controller and I enabled trace in web.config, but nothing was shown on any of the pages for the controller about the trace information (I just got original page, appending trace.axd does not work either!)</p>
  
  <p>The web.config to enable trace:</p>
  
  <pre><code>&lt;system.web&gt;&lt;trace enabled="true" pageOutput="true" requestLimit="40" localOnly="false"/&gt;&lt;/system.web&gt;
  </code></pre>
  
  <p>OnResultExecuting/OnResultExecuted:</p>
  
  <pre><code>protected override void OnResultExecuting(ResultExecutingContext filterContext)
      {
          string controller = filterContext.RouteData.Values["controller"].ToString();
          string action = filterContext.RouteData.Values["action"].ToString();
          start_time = DateTime.Now;
          System.Diagnostics.Trace.Write(string.Format("Start '{0}/{1}' on: {2}", controller, action, start_time));
      }
  
      protected override void OnResultExecuted(ResultExecutedContext filterContext)
      {
          string controller = filterContext.RouteData.Values["controller"].ToString();
          string action = filterContext.RouteData.Values["action"].ToString();
          var elapsed_time = DateTime.Now - start_time;
          System.Diagnostics.Trace.Write(string.Format("Start '{0}/{1}' on: {2}", controller, action, elapsed_time));
      }
  </code></pre>