title: Why does Session_Start in Global.asax.cs cause performance problems?
body: <p>When I create an empty Session_Start handler in Global.asax.cs it causes a significant hit when rendering pages to the browser.</p>
  
  <p>How to reproduce:</p>
  
  <p>Create an empty ASP.NET MVC 3 web application (I am using MVC 3 RC2).
  Then add a Home controller with this code:</p>
  
  <pre><code>public class HomeController : Controller
  {
    public ActionResult Index()
    {
      return View();
    }
    public ActionResult Number(int id)
    {
      return Content(id.ToString());
    }
  }
  </code></pre>
  
  <p>Next create a view Home/Index.cshtml and place the following in the BODY section:</p>
  
  <pre><code>@for (int n = 0; n &lt; 20; n++)
  { 
    &lt;iframe src="@Url.Content("~/Home/Number/" + n)" width=100 height=100 /&gt;
  }
  </code></pre>
  
  <p>When you run this page, you'll see 20 IFRAMEs appear on the page, each with a number inside it. All I'm doing here is creating a page that loads 20 more pages behind the scenes. Before continuing, take note of how quickly those 20 pages load (refresh the page a few times to repeat the loads).</p>
  
  <p>Next go to your Global.asax.cs and add this method (yes, the method body is empty):</p>
  
  <pre><code>protected void Session_Start()
  {
  }
  </code></pre>
  
  <p>Now run the page again. This time you'll notice that the 20 IFRAMEs load much slower, one after the other about 1 second apart. This is strange because we're not actually doing anything in Session_Start ... it's just an empty method. But this seems to be enough to cause the slowdown in all subsequent pages.</p>
  
  <p>Does anybody know why this is happening, and better yet does anybody have a fix/workaround?</p>
  
  <p>Update</p>
  
  <p>I've discovered that this behavior only occurs when the debugger is attached (running with F5). If you run it without the debugger attached (Ctrl-F5) then it seems to be ok. So, maybe it's not a significant problem but it's still strange.</p>