title: How to hide miniprofiler?
body: <p>I'm using MVC Mini profiler to check the speed of specific parts of my application, and would like to keep it there just in case something happens later and I may need to check "what's going wrong". It's not a full log set, but it comes pretty in handy to know what's making a page take long.</p>
  
  <p>So, my goal is to hide it and have it profile only when the request comes with a specific parameter. However, none of my attempts have worked in the way that I would expect.</p>
  
  <p>This has done the trick of not showing it on the screen (code in a view):</p>
  
  <pre><code>@if (Request.QueryString.AllKeys.Contains("showProfiler"))
  { 
      @MvcMiniProfiler.MiniProfiler.RenderIncludes()
  }
  </code></pre>
  
  <p>This is the attempt that got closer. Correctly hides the mini profiler info, but at the moment I show it, it profiles everything since I stopped showing it. So, let's say that I profile my page and it takes 3 seconds. I remove the query parameter and load the page three more times. I add my parameter again and I see 4 sets of profile information. That implies that it keeps track of everything and I wonder it if could give memory issues.</p>
  
  <p>Attempts to make that not happen anymore:</p>
  
  <p><strong>Attempt 1:</strong></p>
  
  <pre><code>protected void Application_BeginRequest()
  {
      if (Request.QueryString.AllKeys.Contains("showProfiler"))
      {
          MiniProfiler.Start();
      }
  }
  </code></pre>
  
  <p><strong>Attempt 2:</strong></p>
  
  <pre><code>protected void Application_EndRequest()
  {
      MiniProfiler.Stop(!Request.QueryString.AllKeys.Contains("showProfiler"));
  }
  </code></pre>
  
  <p><strong>Attempt 3:</strong></p>
  
  <pre><code>protected void Application_EndRequest()
  {
      MiniProfiler.Stop(true);
  }
  </code></pre>
  
  <p>None of these worked. Any ideas?</p>