When I create an empty Session_Start handler in Global.asax.cs it causes a significant hit when rendering pages to the browser.
How to reproduce:
Create an empty ASP.NET MVC 3 web application (I am using MVC 3 RC2). Then add a Home controller with this code:
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult Number(int id)
{
return Content(id.ToString());
}
}
Next create a view Home/Index.cshtml and place the following in the BODY section:
@for (int n = 0; n < 20; n++)
{
<iframe src="@Url.Content("~/Home/Number/" + n)" width=100 height=100 />
}
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).
Next go to your Global.asax.cs and add this method (yes, the method body is empty):
protected void Session_Start()
{
}
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.
Does anybody know why this is happening, and better yet does anybody have a fix/workaround?
Update
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.