迷你 MVC 分析器:似乎显示每个静态资源的分析时间

发布于 2024-11-19 18:57:04 字数 1504 浏览 3 评论 0原文

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

这种行为是预期的吗?

I've just started using the mvc-mini-profiler (http://code.google.com/p/mvc-mini-profiler/) and I think it's awesome. However, I'm getting some odd behaviour while using it.

I've got an ASP.NET Webforms site running on IIS7.5 and for some reason when I load a page with the profiler enabled, I not only get a time measurement for the aspx page, but I also get it for random css and js resources on the page.

The aspx profile works correctly, with the SQL query also being profiled correctly. However, as the picture shows I also get a bunch of other results which appear to be results for static CSS and JS files. As far as I can tell, these are being served up statically by IIS, so the profiler code shouldn't even be invoked for these.

The relevant parts of my Global.asax are:

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

Is this behaviour expected?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

两个我 2024-11-26 18:57:04

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

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

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

Yes this is correct but it is very easy to filter these out.

Taken from the sample code in the project 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();
}

This lets you filter out what you want to see or not this is a sample of what I have excluded in my web application which i am finding is working for my application

ignored.Add("WebResource.axd");
ignored.Add("ScriptResource.axd");
ignored.Add("/Styles/");
ignored.Add("/Images/");
ignored.Add(".js");
御弟哥哥 2024-11-26 18:57:04

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

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

You can actually put that in one line and also omit the slashes. Like this:

    protected void Application_BeginRequest()
    {
        if (Request.IsLocal)
        {
            MiniProfiler.Start();
            MiniProfiler.Settings.IgnoredPaths = new[] { "static", "webresource.axd", "styles", "images" };
        }
     }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文