C# Mini MVC profiler:似乎正在显示每个静态资源的配置文件时间
我刚刚开始使用mvc mini profiler(),我觉得它很棒。然而,我在使用它时有一些奇怪的行为 我在IIS7.5上运行了一个ASP.NET Webforms站点,出于某种原因,当我加载一个启用了探查器的页面时,我不仅得到了aspx页面的时间度量,而且还得到了页面上随机css和js资源的时间度量 aspx配置文件工作正常,SQL查询的配置也正确。然而,如图所示,我还得到了一系列其他结果,这些结果似乎是静态CSS和JS文件的结果。据我所知,这些都是由IIS静态提供的,因此不应该为这些调用探查器代码 my Global.asax的相关部分包括:C# Mini MVC profiler:似乎正在显示每个静态资源的配置文件时间,c#,asp.net,mvc-mini-profiler,C#,Asp.net,Mvc Mini Profiler,我刚刚开始使用mvc mini profiler(),我觉得它很棒。然而,我在使用它时有一些奇怪的行为 我在IIS7.5上运行了一个ASP.NET Webforms站点,出于某种原因,当我加载一个启用了探查器的页面时,我不仅得到了aspx页面的时间度量,而且还得到了页面上随机css和js资源的时间度量 aspx配置文件工作正常,SQL查询的配置也正确。然而,如图所示,我还得到了一系列其他结果,这些结果似乎是静态CSS和JS文件的结果。据我所知,这些都是由IIS静态提供的,因此不应该为这些调用探查
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);
}
}
这是预期的行为吗?是的,这是正确的,但很容易过滤掉这些行为 取自项目中的示例代码 这可以让你过滤出你想看或不想看的内容这是我在我的web应用程序中排除的内容的一个示例,我发现它适用于我的应用程序
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" };
}
}
我在最新代码中注意到的一点是,有一些调试代码留在了IE中,并导致IE出现一些问题。我已在问题跟踪程序问题53上记录了一个问题,我将密切关注-谢谢。我们所有的开发者都在Chrome/FF上,所以我并不担心。
protected void Application_BeginRequest()
{
if (Request.IsLocal)
{
MiniProfiler.Start();
MiniProfiler.Settings.IgnoredPaths = new[] { "static", "webresource.axd", "styles", "images" };
}
}