c# - 迷你 MVC 探查器 : appears to be displaying profile times for every static resource

标签 c# asp.net mvc-mini-profiler

我刚刚开始使用 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);
        }
    }

这种行为是预期的吗?

最佳答案

是的,这是正确的,但很容易将它们过滤掉。

取自项目中的示例代码Source

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

关于c# - 迷你 MVC 探查器 : appears to be displaying profile times for every static resource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6648249/

相关文章:

c# - 实现 JavaScript 代码与控制台应用程序 C# 之间的通信

c# - WCF REST 服务如何接收字节数组,而不是流

javascript - 客户端如何存储动态图像

extjs - ServiceStack MiniProfiler Ajax 请求日志记录

c# - 尝试更改 DataGrid 中的单元格颜色时出现 WPF 表单中的 InvalidOperationException

c# - 如何创建代理以收听表单上的所有文本框

asp.net - IIS7.5 上的静态文件处理程序不提供脚本

asp.net - 需要向第三方提供有关 REST URL 的建议以访问我的网站

entity-framework - mvc-mini-profiler 减慢 Entity Framework

asp.net-mvc - 如何使ASP.NET MVC微型分析器与Linq 2 SQL一起使用?