Mini MVC 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(); } 

这可以让你过滤掉你想要看到的内容,这是我在我的网络应用程序中排除的样本,我发现它正在为我的应用程序工作

 ignored.Add("WebResource.axd"); ignored.Add("ScriptResource.axd"); ignored.Add("/Styles/"); ignored.Add("/Images/"); ignored.Add(".js"); 

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

  protected void Application_BeginRequest() { if (Request.IsLocal) { MiniProfiler.Start(); MiniProfiler.Settings.IgnoredPaths = new[] { "static", "webresource.axd", "styles", "images" }; } }