mvc-mini-profiler for users in a particular role

When Jeff Atwood announced the release of the mvc-mini-profiler for ASP.NET MVC Web sites I was intrigued. Just the other day he wrote an article Performance is a Feature and I decided I could hold off no longer.

Tonight (for better or worse) I finally got this up and running on one of my sites, and fully intend on adding it to at least one more.

To install it I naturally used NuGet, but note that it's called MiniProfiler there.

Next, I had to add the necessary code to my _layout.cshtml, which also required that I move my jQuery include to the head element. Unfortunate, but ... that's how it is.

Finally, since I only wanted this to show for users in a particular role I added the below to the global.asax.cs:

protected void Application_BeginRequest()
{
	MiniProfiler.Start();
}

protected void Application_AuthorizeRequest(Object sender, EventArgs e) { if (!User.IsInRole(“Administrator”)) { MvcMiniProfiler.MiniProfiler.Stop(discardResults: true); } }

protected void Application_EndRequest() { MiniProfiler.Stop(); }

And with that done, I can see that my pages load extremely quick (after the first time of course).

I definitely need to do some research to see if I can display the total time for all users, albeit in a slightly different position (footer of the page), as that's something I wouldn't mind showing to users.