MVC - Mini Profiler
by
Jeremy Canfield |
Updated: March 20 2020
| MVC articles
Install the mini profiler.
- In Visual Studio, select Tools > NuGet Package Manager > Package Manager Console.
- Type install-package miniprofiler and press enter.
Add the following to the global.asax file.
using StackExchange.Profiling;
protected void Application_BeginRequest()
{
if (Request.IsLocal)
{
MiniProfiler.Start();
}
}
protected void Application_EndRequest()
{
MiniProfiler.Stop();
}
Add the following to the head of the _Layout.cshtml file.
@MvcMiniProfiler.MiniProfiler.RenderIncludes()
Add the following to the web.config file.
<system.webServer>
<handlers>
<add name="MiniProfiler" path="mini-profiler-resources/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
</handlers>
The source of the page should now have the following HTML:
<script async type="text/javascript" id="mini-profiler" src="/mini-profiler-resources/includes.js"...>
A small div should now appear near the upper left-hand corner of your site. Selecting the div will show details.
By default, the mini profiler will appear on your home page (www.freekb.net/Home/Index in this example), but will not appear on other pages.
Did you find this article helpful?
If so, consider buying me a coffee over at