zoukankan      html  css  js  c++  java
  • 实例分析ASP.NET在MVC5中使用MiniProfiler监控MVC性能的方法 �

    这篇文章主要为大家详细介绍了ASP.NET MVC5使用MiniProfiler监控MVC性能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

    MiniProfiler ,一个简单而有效的迷你剖析器,可以有效的实时监控页面。通过直接引用、Ajax、Iframe形式访问的其它页面进行监控,监控内容包括数据库内容,并可以显示数据库访问的SQL。

    1.安装

    首先新建一个 asp.net mvc 项目

    右键项目,管理NuGet程序包。 安装 MiniProfiler.Mvc4和MiniProfiler

    ps:MiniProfiler.MVC4的NuGet包(该MVC4包支持MVC5)

    或者也可以打开程序包管理控制台 输入命令进行安装

    Install-Package MiniProfiler -Version 3.2.0.157

    Install-Package MiniProfiler.Mvc4 -Version 3.0.11

    2.将以下内容添加到Application_Start()Global.asax中

     

    protected void Application_Start()
    {
     ...
     GlobalFilters.Filters.Add(new ProfilingActionFilter());
    
     var copy = ViewEngines.Engines.ToList();
     ViewEngines.Engines.Clear();
     foreach (var item in copy)
     {
      ViewEngines.Engines.Add(new ProfilingViewEngine(item));
     }
    }

    3.将以下内容添加到“Application_BeginRequest()”和“Application_EndRequest()”,也在Global.asax中

     

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

    4.将以下内容添加到_Layout.cshtml(就在</body>标签之前):

     

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

    5.将以下内容添加到<handlers>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>

    如果你在项目中使用了Entity Framework ,那么你可以安装MiniProfiler.EF6软件包,在Application_Start()在Global.asax 结尾添加了以下内容: MiniProfilerEF6.Initialize();

    一个简单的对MVC性能的监控就这样了,其实他还有很多功能,比如说能够通过不同的参数检测并突出显示执行相同查询的区域。这样您就可以快速找到可能批量的查询。

    还可以记录所有的ajax的调用,查看最近100个分析请求的分析信息等。

    结果展示:

    以上就是实例分析ASP.NET在MVC5中使用MiniProfiler监控MVC性能的方法的详细内容,更多请关注php中文网其它相关文章!

    • 相关标签:MiniProfiler ASP.NET MVC5
    • 本文原创发布php中文网 ,转载请注明出处,感谢您的尊重!
  • 相关阅读:
    基于redis实现的延迟消息队列
    Redis实现求交集操作结果缓存的设计方案
    限流算法之漏桶算法、令牌桶算法
    Apache设置防DDOS模块mod_evasive
    FastCGI技术
    详解强大的SQL注入工具——SQLMAP
    nginx根据域名做http,https分发
    Nginx配置SSL证书部署HTTPS网站
    JProfiler学习笔记
    Mysql压测工具mysqlslap 讲解
  • 原文地址:https://www.cnblogs.com/webenh/p/9796764.html
Copyright © 2011-2022 走看看