MiniProfiler没有出现在asp.net MVC上

Dim*_*imo 23 c# asp.net-mvc profiler mvc-mini-profiler

我把它添加到我的Global.asax.cs:

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

protected void Application_EndRequest()
{
    MiniProfiler.Stop();
}
Run Code Online (Sandbox Code Playgroud)

我补充道

@MiniProfiler.RenderIncludes()
Run Code Online (Sandbox Code Playgroud)

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

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

 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");
        }
    }
Run Code Online (Sandbox Code Playgroud)

但我的页面上没有显示任何内容,也没有任何配置文件框.

在查看源代码时我只看到这个:

<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>
Run Code Online (Sandbox Code Playgroud)

Ald*_*den 43

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

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

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

GlobalFilters.Filters.Add(new StackExchange.Profiling.MVCHelpers.ProfilingActionFilter());
Run Code Online (Sandbox Code Playgroud)

  • 此外虽然,"无关"的说明在这个解决方案的底部需要MiniProfiler.MVC包之一,和MVC4 +包现在有ProfilingActionFilter的StackExchange.Profiling.Mvc命名空间下代替. (8认同)
  • 这里的答案和评论对我有所帮助,但我还需要做其他事情.我认为列出所有步骤会很有帮助; 我在这里的答案中做了:http://stackoverflow.com/a/31568406/593751 (2认同)