25

I added this to my Global.asax.cs:

protected void Application_BeginRequest()
{
    if (Request.IsLocal)
    {
        MiniProfiler.Start();
    }
}

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

I added

@MiniProfiler.RenderIncludes()

just below the </body> tag in _Layout.cshtml.

In my controller I'm using:

 public class HomeController : Controller
    {
        public ActionResult Index()
        {    
            var profiler = MiniProfiler.Current; // it's ok if this is null
            using (profiler.Step("Set page title"))
            {
                ViewBag.Title = "Home Page";
            }
            using (profiler.Step("Doing complex stuff"))
            {
                using (profiler.Step("Step A"))
                { // something more interesting here
                    Thread.Sleep(100);
                }
                using (profiler.Step("Step B"))
                { // and here
                    Thread.Sleep(250);
                }
            }

            return View("~/Views/Home/Index.cshtml");
        }
    }

But nothing is showing up on my page, no profile box.

When doing viewing the source code I only see this:

<script async type="text/javascript" id="mini-profiler" src="/mini-profiler-resources/includes.js?v=xwYPDDH1blvqmxgsBweNC++H7CFU3KGQ+zFcVlJPsXw=" data-version="xwYPDDH1blvqmxgsBweNC++H7CFU3KGQ+zFcVlJPsXw=" data-path="/mini-profiler-resources/" data-current-id="6d24704e-3003-44f8-9965-437c6275d639" data-ids="8ec2c718-4375-4d3f-9b69-4092e534143e,6d24704e-3003-44f8-9965-437c6275d639" data-position="left" data-trivial="false" data-children="false" data-max-traces="15" data-controls="false" data-authorized="true" data-toggle-shortcut="Alt+P" data-start-hidden="false"></script>
tereško
  • 58,060
  • 25
  • 98
  • 150
Dimo
  • 3,238
  • 6
  • 29
  • 46

3 Answers3

43

In your web.config, add this:

<system.webServer>
    ...
    <handlers>
        <add name="MiniProfiler" path="mini-profiler-resources/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
        ...
    </handlers>
    ...

If you want some sweet MVC Action profiling (unrelated to your problem), add this line to Application_Start in Global.asax.cs:

GlobalFilters.Filters.Add(new StackExchange.Profiling.MVCHelpers.ProfilingActionFilter());
Alden
  • 6,553
  • 2
  • 36
  • 50
  • Still the valid answer as of today! – Jim Yarbro Nov 01 '14 at 08:33
  • 8
    Additionally though, the "unrelated" note at the bottom of this solution requires one of the MiniProfiler.MVC packages, and the MVC4+ package now has ProfilingActionFilter under the StackExchange.Profiling.Mvc namespace instead. – Jim Yarbro Nov 01 '14 at 08:38
  • getting error at `.MVCHelpers.ProfilingActionFilter()` – sridharnetha May 21 '15 at 08:17
  • 1
    In the build of MiniProfiler.MVC4 that I just got from nuget its just `StackExchange.Profiling.Mvc` for the namespace. – Chris Jul 27 '15 at 10:53
  • According to the miniprofilier page, this handler should be added if runAllManagedModulesForAllRequests is set to false http://miniprofiler.com/ – usefulBee Jan 26 '16 at 21:04
  • 2
    The answers and comments here helped me, but there were other things that I needed to do. I thought it would be helpful to list all the steps; which I did in my answer here: http://stackoverflow.com/a/31568406/593751 – DigitalDan Feb 22 '16 at 09:44
1

If anybody tried Alden's solution and still does not work for you, try setting discardResults to false as suggested by willgrosett

   // Global.asax.cs file
   protected void Application_BeginRequest()
    {
        if (Request.IsLocal)
        {
            MiniProfiler.Start();
        }
    }

    protected void Application_EndRequest(object sender, EventArgs e)
    {
        MiniProfiler.Stop(discardResults: false);
    }
usefulBee
  • 9,250
  • 10
  • 51
  • 89
1

In MiniProfiler latest version:4.0.165. Be sure you added the code in Application_Start()

protected void Application_Start()
{
    ...
    MiniProfiler.Configure(new MiniProfilerOptions());//default setting
    MiniProfilerEF6.Initialize();
}

Doc is here: https://miniprofiler.com/dotnet/AspDotNet

And in latest version, you don't need add

<system.webServer>
    ...
    <handlers>
        <add name="MiniProfiler" path="mini-profiler-resources/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
        ...
    </handlers>
    ...

in Web.config anymore.

Jim
  • 489
  • 5
  • 11