使用MiniProfiler与MVC 5 [英] Using MiniProfiler with MVC 5

查看:299
本文介绍了使用MiniProfiler与MVC 5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

修改
得到的答案<一个href=\"http://stackoverflow.com/questions/18790507/miniprofiler-not-showing-up-on-asp-net-mvc?rq=1\">here

所以,我想退房MiniProfiler解决一些性能问题。
用它生产code之前,我想与尝试它的一个样本,以便与创建一个MVC应用5径自。这是一个被通过该模板​​创建纯香草应用程序。

So I wanted to check out MiniProfiler to troubleshoot some performance issues. Before using it on production code I wanted to try it out with the a sample so went ahead with creating a MVC 5 application. This is plain vanilla app that gets created with the template.

添加此code中的HomeController的Index()方法:

Added this code in the Index() method of HomeController:

var profiler = MiniProfiler.Current;
        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();

增加了jQuery的包下面这一行_layout:

Added this line below the jquery bundle in _Layout:

@Scripts.Render("~/bundles/jquery")
@StackExchange.Profiling.MiniProfiler.RenderIncludes()

@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)

然的应用程序。
什么也不显示。无纹,什么都没有。

Ran the app. Nothing shows up. No profiling, nothing.

我是什么失踪?

问候。

推荐答案

这是我必须做的就是MiniProfiler在我的 ASP.NET MVC5 项目的工作:

This is what I had to do to get MiniProfiler working in my ASP.NET MVC5 project:


  1. 安装在 MiniProfiler MiniProfiler.MVC4 的NuGet包(该MVC4包支持MVC5)

  1. Installed the MiniProfiler and MiniProfiler.MVC4 NuGet packages (the MVC4 package supports MVC5)

添加以下的Application_Start()在Global.asax中:

Add the following to Application_Start() in Global.asax:

protected void Application_Start()
{
    ...
    // Setup profiler for Controllers via a Global ActionFilter
    GlobalFilters.Filters.Add(new ProfilingActionFilter());

    // initialize automatic view profiling
    var copy = ViewEngines.Engines.ToList();
    ViewEngines.Engines.Clear();
    foreach (var item in copy)
    {
        ViewEngines.Engines.Add(new ProfilingViewEngine(item));
    }
}


  • 添加以下的Application_BeginRequest()'和'Application_EndRequest()',也是在Global.asax中:

  • Add the following to 'Application_BeginRequest()' and 'Application_EndRequest()', also in Global.asax:

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


  • 添加以下_Layout.cshtml(之前的&LT; /身体GT; 标记):

        ...
        @StackExchange.Profiling.MiniProfiler.RenderIncludes()
    </body>
    </html>
    


  • 添加以下到&LT;&处理GT; Web.config文件的部分:

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


  • 这足以简介每个MVC控制器动作和视图。

    That was enough to profile each of the MVC Controller Actions and Views.

    在我的特定的项目我使用实体框架6,所以我也做了以下内容:

    In my particular project I was using Entity Framework 6, so I also did the following:

    一)安装在 MiniProfiler.EF6

    二)增加了以下为的Application_Start年底()在Global.asax中:

    b) Added the following to the end of Application_Start() in Global.asax:

        ...
        MiniProfilerEF6.Initialize();
    }
    

    这篇关于使用MiniProfiler与MVC 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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