Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove specific URL's from profiling when using MiniProfiler

Sometimes when using the miniprofiler, there's just some requests that you doesn't care about. In my case I don't care much about signalr, umbraco pings, and some requests made when I wanna know if the user is idle or not.

To avoid the miniprofiler using energy on (and providing results for) these types of requests, I have added the following code to my global.asax.cs file:

protected void Application_BeginRequest()
{
    if (
        (Request.IsLocal || Request.UserHostAddress == "37.49.143.197")
        && !(Request.RawUrl.Contains("/signalr/")
            || Request.RawUrl.Contains("/idle/verify")
            || Request.RawUrl.Contains("/idle/interaction")
            || Request.RawUrl.Contains("/umbraco/ping")
            )
        )
    {
        MiniProfiler.Start();
    }
}

Seeing that I still recieve results for URL's containing the given strings, I have made this check later on in the Application Life Cycle in an attempt on removing the unwanted results I could see that I still got.

protected void Application_ProcessRequest()
{
    if (Request.RawUrl.Contains("/signalr/")
        || Request.RawUrl.Contains("/idle/verify")
        || Request.RawUrl.Contains("/idle/interaction")
        || Request.RawUrl.Contains("/umbraco/ping")
        )
    {
        MiniProfiler.Stop(discardResults: true);
    }
}

But even though I have done this, I am still recieving the unwanted results. Does anyone know how this can be, what am I doing wrong here?

Notes

It should be noted that because I'm using Umbraco as my fundament, I'm using MiniProfiler 2.1.0 and I start out my Global.asax.cs file like this:

public class MvcApplication : UmbracoApplication
{    
    protected override void OnApplicationStarted(object sender, EventArgs e)
    {
        // Setup profiler for Controllers via a Global ActionFilter
        GlobalFilters.Filters.Add(new ProfilingActionFilter());

        // initialize automatic view profiling
        var copy = ViewEngines.Engines.ToList();
        ViewEngines.Engines.Clear();
        foreach (var item in copy)
        {
            ViewEngines.Engines.Add(new ProfilingViewEngine(item));
        }
    ...
like image 889
Squazz Avatar asked Apr 05 '16 12:04

Squazz


1 Answers

Have you tried using IgnoredPaths?

protected void Application_Start()
{
    var ignored = MiniProfiler.Settings.IgnoredPaths.ToList();
    ignored.Add("/signalr/");        
    ignored.Add("/idle/verify");
    ignored.Add("/idle/interaction");
    ignored.Add("/umbraco/ping");
    MiniProfiler.Settings.IgnoredPaths = ignored.ToArray();
}

The reason I think this will work is that the BeginRequest and EndRequest events are not fired for static resources.

My theory is that some of your requests are indeed for static content, and hence the events you are describing won't fire.

With your Umbraco structure, the code would look like this:

protected override void OnApplicationStarted(object sender, EventArgs e)
{
    var ignored = MiniProfiler.Settings.IgnoredPaths.ToList();
    ignored.Add("/signalr/");        
    ignored.Add("/idle/verify");
    ignored.Add("/idle/interaction");
    ignored.Add("/umbraco/ping");
    MiniProfiler.Settings.IgnoredPaths = ignored.ToArray();

    // Setup profiler for Controllers via a Global ActionFilter
    GlobalFilters.Filters.Add(new ProfilingActionFilter());

    // initialize automatic view profiling
    var copy = ViewEngines.Engines.ToList();
    ViewEngines.Engines.Clear();
    foreach (var item in copy)
    {
        ViewEngines.Engines.Add(new ProfilingViewEngine(item));
    }
}
like image 51
Mathias Lykkegaard Lorenzen Avatar answered Oct 04 '22 16:10

Mathias Lykkegaard Lorenzen