12

enter image description hereHow can I use miniprofiler in asp.net web site(NOT FOR MVC)? There are many resources for MVC but I can not find anything for web site.

Thanks to Alex. Now it works for asp.net web site. But I can not understand what it displays. I have not written any code in method. See the image below.

Code is as below for which I ran profiler.

protected void Page_Load(object sender, EventArgs e)
{
    using (MiniProfiler.Current.Step("test"))
    {
        Page.Title = "12345";
    }
}
Microsoft Developer
  • 5,229
  • 22
  • 93
  • 142

1 Answers1

27

From the miniprofiler.com:

PM> Install-Package MiniProfiler

in your global.asax:

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

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

and then somewhere in your master page:

<%= StackExchange.Profiling.MiniProfiler.RenderIncludes() %>

This should be enough for starting.

Oleks
  • 31,955
  • 11
  • 77
  • 132
  • Thanks Alex, now I can see the profiler but I can not understand what does it all means. Can you please guide me? See the code and image that I have attached with edited question. – Microsoft Developer Feb 26 '13 at 11:17
  • 1
    @ChiragFanse: by using `MiniProfiler.Current.Step("test")` you're creating a *profile step* called "test". Typically you could put some *heavy logic* into steps, and then see the stats for these steps. – Oleks Feb 26 '13 at 12:13
  • When I look at where <%= StackExchange.Profiling.MiniProfiler.RenderIncludes() %> is in the rendered HTML in the browser nothing appears there. But no errors or anything. – Matthew Lock May 01 '14 at 07:34
  • @MatthewLock: are you sure you started MP in the begin request event handler? – Oleks May 01 '14 at 09:48
  • Yes. I even put a breakpoint on it, to confirm that it was being called. – Matthew Lock May 01 '14 at 10:01
  • @Alex : Can you please explain me the purpose of RenderIncludes() method? – Ankita Jan 19 '15 at 11:37
  • @Ankita: `RenderIncludes` writes out necessary scripts and styles for miniprofiler to show – Oleks Jan 19 '15 at 11:57
  • @Alex: Thank you. Can you please help me with this question-[http://stackoverflow.com/questions/25255960/miniprofiler-current-method-does-not-return-the-time] – Ankita Jan 19 '15 at 12:03
  • Check if runAllManagedModulesForAllRequests is true on your web.config – rodrigorf May 01 '17 at 23:59