How to hide miniprofiler?

早过忘川 提交于 2019-12-05 00:49:53

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

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


EDIT:

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.

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?

Just start the profiler like normal in your begin request event. Then in your controller or view, check for the query string and call MiniProfiler.Stop(true) to discard the profiled data if it doesn't or is set to false.

protected void Application_BeginRequest()
{
    MiniProfiler.Start();  
}

Then in your view:

@if(!Request.QueryString.AllKeys.Contains("profiling"))
{
    MiniProfiler.Stop(true);
}

I did't find a solution in above.

For me the only solution was to set the debug="false" in the Web.Config file.

<compilation defaultLanguage="c#" debug="false" batch="false" targetFramework="4.5.2">

Hope this helps for other as well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!