如何在使用MiniProfiler时从特征分析中删除特定URL

时间:2023-01-20 09:48:35

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.

有时候使用miniprofiler时,只有一些你不关心的请求。在我的情况下,我不太关心信号器,umbraco ping,以及当我想知道用户是否闲置时提出的一些请求。

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:

为了避免miniprofiler在这些类型的请求中使用能量(并提供结果),我将以下代码添加到我的global.asax.cs文件中:

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.

看到我仍然收到包含给定字符串的URL的结果,我在应用程序生命周期中稍后进行了此检查,试图消除我可以看到的不必要的结果。

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:

应该注意的是,因为我使用Umbraco作为我的基础,我使用MiniProfiler 2.1.0并且我开始我的Global.asax.cs文件,如下所示:

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));
        }
    ...

1 个解决方案

#1


4  

Have you tried using IgnoredPaths?

您是否尝试过使用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.

我认为这将起作用的原因是不会为静态资源触发BeginRequest和EndRequest事件。

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:

使用您的Umbraco结构,代码如下所示:

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));
    }
}

#1


4  

Have you tried using IgnoredPaths?

您是否尝试过使用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.

我认为这将起作用的原因是不会为静态资源触发BeginRequest和EndRequest事件。

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:

使用您的Umbraco结构,代码如下所示:

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));
    }
}