How To Install Mini Profiler With EpiServer

Page load speed is an essential factor in any business web delivery plan. If a web page takes too long to load, site visitors will simply jump ship and go somewhere else. EpiServer comes with a few basic in-built tools that can help you refine your page load times, but, in my opinion, if you are really serious about performance you will need to use third-party tools specifically targeted towards performance. One tool I would recommend looking into is MiniProfiler.

How To Install Mini Profiler In EpiServer

Mini profiler can be installed via NuGet, in Visual Studio open your package explorer by right-clicking on your solution and selecting ‘Manage NuGet Packages’.

episerver_mini_profiler

Type in ‘Mini Profiler’ and click install.

Configuring Mini Profiler from here is pretty easy. Add the following code into your Global.ascx.

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

Add this into your web.config:

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

In your master layout, you will need to add this snippet of code:

@using StackExchange.Profiling;
@MiniProfiler.RenderIncludes()

Now when you try and run your website…

episerver_mini_profiler_4

In the top left, you should see the mini=profiler tab available.

How To Measure Your Code

There are various ways you can architecture your performance monitoring code into solution. I would advise trying to follow the open/close principle and mix and match your monitoring and production code. When you architect your solution, if you use an IoC like structure map, you can keep this code separate.

For the code you want to profile, you can use this code:

var profiler = MiniProfiler.Current;
using (profiler.Step("Stap Name"))
{
// Do something
}

Jon D Jones

Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge

More Posts

3 replies
  1. Arve
    Arve says:

    Hi Jon,

    What do you mean by “There are various ways you can architecture your performance monitoring code into solution. I would advise trying to follow the open/close principle and mix and match your monitoring and production code.”?

    Thanks

    Reply
    • Jon D Jones
      Jon D Jones says:

      I’ll need to write a new post as it’s quite long. The main point is you try to separate your profiling logic from your production code. If you create a class called something like a ProfileContentRepository that inherits from IContentRepository, add the profile code in their and then have that class call down to the underlining Epi API, allows you to have configurable profiling logging extracted from your code base

      Reply

Trackbacks & Pingbacks

  1. […] The Episerver profile can useful but it is limited. There are a number of more advanced third-party tools available and one that I recommend you experiment with is MiniProfiler If you want more information about mini-profiler, I suggest you read, How To Install MiniProfiler With Episerver. […]

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *