【问题标题】:MiniProfiler not showing up on asp.net MVCMiniProfiler 未显示在 asp.net MVC 上
【发布时间】:2013-09-18 09:19:54
【问题描述】:

我将此添加到我的 Global.asax.cs:

protected void Application_BeginRequest()
{
    if (Request.IsLocal)
    {
        MiniProfiler.Start();
    }
}

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

我加了

@MiniProfiler.RenderIncludes()

就在 _Layout.cshtml 中的 </body> 标记下方。

在我正在使用的控制器中:

 public class HomeController : Controller
    {
        public ActionResult Index()
        {    
            var profiler = MiniProfiler.Current; // it's ok if this is null
            using (profiler.Step("Set page title"))
            {
                ViewBag.Title = "Home Page";
            }
            using (profiler.Step("Doing complex stuff"))
            {
                using (profiler.Step("Step A"))
                { // something more interesting here
                    Thread.Sleep(100);
                }
                using (profiler.Step("Step B"))
                { // and here
                    Thread.Sleep(250);
                }
            }

            return View("~/Views/Home/Index.cshtml");
        }
    }

但我的页面上没有显示任何内容,没有个人资料框。

查看源代码时,我只看到:

<script async type="text/javascript" id="mini-profiler" src="/mini-profiler-resources/includes.js?v=xwYPDDH1blvqmxgsBweNC++H7CFU3KGQ+zFcVlJPsXw=" data-version="xwYPDDH1blvqmxgsBweNC++H7CFU3KGQ+zFcVlJPsXw=" data-path="/mini-profiler-resources/" data-current-id="6d24704e-3003-44f8-9965-437c6275d639" data-ids="8ec2c718-4375-4d3f-9b69-4092e534143e,6d24704e-3003-44f8-9965-437c6275d639" data-position="left" data-trivial="false" data-children="false" data-max-traces="15" data-controls="false" data-authorized="true" data-toggle-shortcut="Alt+P" data-start-hidden="false"></script>

【问题讨论】:

    标签: c# asp.net-mvc profiler mvc-mini-profiler


    【解决方案1】:

    在 MiniProfiler 最新版本:4.0.165。确保您在 Application_Start() 中添加了代码

    protected void Application_Start()
    {
        ...
        MiniProfiler.Configure(new MiniProfilerOptions());//default setting
        MiniProfilerEF6.Initialize();
    }
    

    文档在这里:https://miniprofiler.com/dotnet/AspDotNet

    在最新版本中,您不需要添加

    <system.webServer>
        ...
        <handlers>
            <add name="MiniProfiler" path="mini-profiler-resources/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
            ...
        </handlers>
        ...
    

    不再在 Web.config 中了。

    【讨论】:

      【解决方案2】:

      如果有人尝试了 Alden 的解决方案但仍然无法为您工作,请尝试按照 willgrosett 的建议将 discardResults 设置为 false

         // Global.asax.cs file
         protected void Application_BeginRequest()
          {
              if (Request.IsLocal)
              {
                  MiniProfiler.Start();
              }
          }
      
          protected void Application_EndRequest(object sender, EventArgs e)
          {
              MiniProfiler.Stop(discardResults: false);
          }
      

      【讨论】:

      • discardResults: 的默认值为 false
      【解决方案3】:

      在您的 web.config 中,添加以下内容:

      <system.webServer>
          ...
          <handlers>
              <add name="MiniProfiler" path="mini-profiler-resources/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
              ...
          </handlers>
          ...
      

      如果您想要一些甜蜜的 MVC 动作分析(与您的问题无关),请将此行添加到 Global.asax.cs 中的Application_Start

      GlobalFilters.Filters.Add(new StackExchange.Profiling.MVCHelpers.ProfilingActionFilter());
      

      【讨论】:

      • 今天仍然是有效答案!
      • 此外,此解决方案底部的“不相关”注释需要 MiniProfiler.MVC 包之一,而 MVC4+ 包现在在 StackExchange.Profiling.Mvc 命名空间下具有 ProfilingActionFilter。跨度>
      • .MVCHelpers.ProfilingActionFilter() 出现错误
      • 在我刚刚从 nuget 获得的 MiniProfiler.MVC4 的构建中,命名空间只有 StackExchange.Profiling.Mvc
      • 这里的答案和 cmets 对我有帮助,但我还需要做其他事情。我认为列出所有步骤会有所帮助;我在这里的回答中所做的:stackoverflow.com/a/31568406/593751
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多