28

我刚刚开始使用 mvc-mini-profiler ( http://code.google.com/p/mvc-mini-profiler/ ),我认为它很棒。但是,我在使用它时遇到了一些奇怪的行为。

我有一个在 IIS7.5 上运行的 ASP.NET Webforms 站点,由于某种原因,当我加载启用了探查器的页面时,我不仅获得了 aspx 页面的时间测量,而且还获得了随机 css 和页面上的js资源。

aspx 配置文件正常工作,SQL 查询也被正确配置。但是,如图所示,我还得到了一堆其他结果,这些结果似乎是静态 CSS 和 JS 文件的结果。据我所知,这些是由 IIS 静态提供的,因此甚至不应该为这些调用探查器代码。

我的 Global.asax 的相关部分是:

    protected void Application_BeginRequest()
    {
        MiniProfiler profiler = null;

        // might want to decide here (or maybe inside the action) whether you want
        // to profile this request - for example, using an "IsSystemAdmin" flag against
        // the user, or similar; this could also all be done in action filters, but this
        // is simple and practical; just return null for most users. For our test, we'll
        // profile only for local requests (seems reasonable)
        profiler = MiniProfiler.Start();

        using (profiler.Step("Application_BeginRequest"))
        {
            // you can start profiling your code immediately
        }
    }

    protected void Application_EndRequest()
    {
        MvcMiniProfiler.MiniProfiler.Stop();
    }

    protected void Application_AuthenticateRequest(object sender, EventArgs e)
    {
        if (User == null || !User.Identity.IsAuthenticated)
        {
            MvcMiniProfiler.MiniProfiler.Stop(true);
        }
    }

这种行为是预期的吗?

4

2 回答 2

45

是的,这是正确的,但很容易过滤掉这些。

取自项目源码中的示例代码

void Application_Start(object sender, EventArgs e)
{
    // Code that runs on application startup

    // some things should never be seen
    var ignored = MiniProfiler.Settings.IgnoredPaths.ToList();

    ignored.Add("WebResource.axd");
    ignored.Add("/Styles/");

    MiniProfiler.Settings.IgnoredPaths = ignored.ToArray();
}

这使您可以过滤掉您想要查看的内容这是我在我的 Web 应用程序中排除的示例,我发现它适用于我的应用程序

ignored.Add("WebResource.axd");
ignored.Add("ScriptResource.axd");
ignored.Add("/Styles/");
ignored.Add("/Images/");
ignored.Add(".js");
于 2011-07-11T13:09:00.400 回答
1

您实际上可以将其放在一行中,也可以省略斜杠。像这样:

    protected void Application_BeginRequest()
    {
        if (Request.IsLocal)
        {
            MiniProfiler.Start();
            MiniProfiler.Settings.IgnoredPaths = new[] { "static", "webresource.axd", "styles", "images" };
        }
     }
于 2013-12-04T18:31:59.533 回答