Using MiniProfiler with a hybrid asp.net Web Forms / MVC application - Part 2
Part 1 covered creating a hybrid ASP.NET WebForms / MVC project, adding MiniProfiler to the project, showing MiniProfiler output on the WebForms page and adding an event to the MiniProfiler output. In this part I'll show how to make an AJAX call to a controller action and instrument the action so that the activities that take place in it show up in the MiniProfiler output (this is the easy bit!).
The code for this solution can be found on GitHub at https://github.com/robertwray/BlogStuff in the MiniProfilerWithWebFormsAndMvc project.
Create and instrument a controller
The controller consists of:
alert('Data has been received, you should be able to see this having happened in MiniProfiler (server AND client side)');
With that code added, hitting F5 and starting the project will load the page and show a bit more information in the MiniProfiler window:
Automatically instrumenting Controller actions
There is a built-in (to MiniProfiler.Mvc) way to instrument calls to controller methods, and that's to use the ProfilingActionFilter from the StackExchange.Profiling.Mvc namespace by adding it to your GlobalFilterCollection. This is usally done by having a class called FilterConfig in the App_Start folder (which may already be present in your project), which will basically look like this:
public class FilterConfig
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
And then having a call to
in the Application_Start method of Global.asax. Once this is in place, every call to a controller action will automatically add to the output in MiniProfiler:
This screen-grab also shows off the "show trivial"/"hide trivial" link that you can click on if some of the logged actions took such a short amount of time, that they don't warrant showing by default. By doing this, MiniProfiler gets the "noise" out of the way and you only see the parts of the profiled operation that are taking the time.
My skillset has matured somewhat since then, which you'll probably see from the posts here. You can read a bit more about me on the about page of the site, or check out some of the other posts on my areas of interest.