如何隐藏miniprofiler? [英] How to hide miniprofiler?

查看:245
本文介绍了如何隐藏miniprofiler?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MVC微型分析器来检查我的应用程序的特定部分的速度,并想以防万一有保持它发生后,我可能需要检查什么错。这不是一个完整的日志集,但它涉及pretty派上用场知道什么使一个网页需要很长时间。

I'm using MVC Mini profiler to check the speed of specific parts of my application, and would like to keep it there just in case something happens later and I may need to check "what's going wrong". It's not a full log set, but it comes pretty in handy to know what's making a page take long.

所以,我的目标是隐藏它,并把它配置文件只有当请求带有特定参数。然而,没有我的尝试中,我会期望的方式工作过。

So, my goal is to hide it and have it profile only when the request comes with a specific parameter. However, none of my attempts have worked in the way that I would expect.

这做不显示在屏幕上(code在一个视图)的伎俩:

This has done the trick of not showing it on the screen (code in a view):

@if (Request.QueryString.AllKeys.Contains("showProfiler"))
{ 
    @MvcMiniProfiler.MiniProfiler.RenderIncludes()
}

这是走近了尝试。正确地隐藏了微型探查器的信息,但我表现出来的那一刻,它,因为我不再显示它型材的一切。所以,让我们说,我分析我的网页,它需要3秒钟。我删除了查询参数和三次加载页​​面。我又加我的参数,我看到4台个人资料信息。这意味着,它让一切的轨道,我不知道它是否能够给内存问题。

This is the attempt that got closer. Correctly hides the mini profiler info, but at the moment I show it, it profiles everything since I stopped showing it. So, let's say that I profile my page and it takes 3 seconds. I remove the query parameter and load the page three more times. I add my parameter again and I see 4 sets of profile information. That implies that it keeps track of everything and I wonder it if could give memory issues.

试图建立没有再发生了:

Attempts to make that not happen anymore:

尝试1:

protected void Application_BeginRequest()
{
    if (Request.QueryString.AllKeys.Contains("showProfiler"))
    {
        MiniProfiler.Start();
    }
}

尝试二:

protected void Application_EndRequest()
{
    MiniProfiler.Stop(!Request.QueryString.AllKeys.Contains("showProfiler"));
}

尝试3:

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

这些都不奏效。任何想法?

None of these worked. Any ideas?

推荐答案

借助主页(参见弃事件探查器会话部分)的探查有使用模式正在寻找:

The home page (see the "Abandoning a Profiler Session section) of the profiler has the usage pattern are looking for:

protected void Application_BeginRequest()
{
   MvcMiniProfiler.MiniProfiler.Start();  
}
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
   if(!CurrentUserIsAllowedToSeeProfiler())
   {
       MvcMiniProfiler.MiniProfiler.Stop(discardResults: true);
   }
}

您实施 CurrentUserIsAllowedToSeeProfiler 将被检查,如果查询字符串包含键触发事件探查器。

Your implementation of CurrentUserIsAllowedToSeeProfiler will be checking if the query string contains the key the trigger the profiler.

修改

您也可以看看他们的示例项目,看看他们如何实现某种情况下禁用它。他们检查,看看你正在通过本地主机访问它,当然,你可以改变,要检查查询字符串来代替。

You can also look at their Example Project to see how they implement disabling it in certain situation. Their check is to see if you are accessing it via localhost, but you could of course change that to check the query string instead.

在此基础上,看来尝试#1应该是的伎俩。请注意,一即关闭和尝试#1之间的区别是前者是寻找查询字符串分析,而你尝试#1检查 showProfiler 。难道刚才是一个简单的查询字符串查询股价?

Based on that, it appears that "Attempt #1" should be the trick. Do note that the difference between the one "that is close" and "attempt #1" is the former is looking for query string profiling, whereas your Attempt #1 is checking for showProfiler. Could it have just been a simple query string mixup?

这篇关于如何隐藏miniprofiler?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆