In this article we will learn about profiling your nopCommerce website with MiniProfiler. Out of the box, nopCommerce comes with MiniProfiler integration. So, in order to start using it, all we need to do is configure it correctly from the administration section. This out of the box integration is quite handy for many developers to see what is causing delay in loading pages.

Introduction

What is nopCommerce?

nopCommerce is an
open-source e-Commerce solution based on ASP.NET MVC and MS SQL Server backend database that contains both a catalog
frontend and an administration tool backend. nopCommerce is one of the best
e-Commerce software available in the market for free and any ASP.NET developer
can download the full source code (available on GitHub) to
customize the solution in any way.

What is MiniProfiler?

MiniProfiler is a
simple but effective library available for profiling ASP.NET websites which
help developers to monitor the performance of the web application. Any
developer can easily improve the performance of a website by using MiniProfiler
library that shows exactly how long it takes for a webpage to load, how long it
takes for a SQL query to run and all the other actions that are being executed
on a web page on run-time.

Out of the box, nopCommerce comes with MiniProfiler
integration. So, in order to start using it, all we need to do is configure it
correctly from the administration section. This out of the box integration is
quite handy for many developers to see what is causing delay in loading pages.

To configure it, go to: Administration > Configuration > All
Settings

Search for the setting “DisplayMiniProfilerInPublicStore”

Enable the setting by changing the value to “True” like this:

Overview of MiniProfiler code in nopCommerce

We can see the MiniProfiler integration in the code in Nop.Web/Global.asax.cs

Open Global.asax.cs and find this in the Application_Start()

We can also find the MiniProfiler code in Application_BeginRequest()

Finally in Application_EndRequest()

Demo of MiniProfiler on nopCommerce public store

Since, we have already enabled MiniProfiler in the administration
section, if we run our website and view the public store, the profiler will be
displayed on the left top corner of the browser windows with the loading time
like this:

Now, if we try to click the profiler, we should be able to view the
loading time for each process along with the loading time that is running on
the homepage:

Customizing the MiniProfiler in nopCommerce

In this section, we will go over different ways of customizing the
MiniProfiler in nopCommerce.

·How to display Miniprofiler
only for admin role

MiniProfile is a very useful tool for store admins and developers in
order to keep a track of loading time of different pages and improve the
performance in terms of loading time so that pages on the store site loads
faster for online shoppers. Many store owner might want to take advantage of
MiniProfiler in nopCommerce but may not want customers to see the loading time
on the public store. In that case, we will have to make some customization in
the source code so that online “admin” can view the loading time (if admin is
logged in).

Now, if we run our
website and view the public store, we will see the profiler with the loading
time like this:

If you click on
profiler, you will get the windows similar to this:

Here, you will notice
that there is an additional column “sql” as the MiniProfiler is profiling our
EF database calls. So, if you click on any loading time for SQL query, you will
get the information like this:

Conclusion

It is simply amazing
to see that MiniProfiler is profiling the database calls while any page is
loading. We can see the time takes for each query on this page and this is a
great way for developers to keep an eye on the performance of the nopCommerce website. In any case, the site or webpage is
loading slow, the developer can troubleshoot the problem and improve the
performance.