How to use Mini Profiler in MVC

Home > Search > How-to
  by

Install the mini profiler.

  1. In Visual Studio, select Tools > NuGet Package Manager > Package Manager Console.
  2. 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. 

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments