首页后端开发ASP.NET实例分析ASP.NET在MVC5中使用MiniProfiler监控MVC性能的方法

实例分析ASP.NET在MVC5中使用MiniProfiler监控MVC性能的方法

时间2024-01-30 13:52:03发布访客分类ASP.NET浏览555
导读:收集整理的这篇文章主要介绍了实例分析ASP.NET在MVC5中使用MiniProfiler监控MVC性能的方法,觉得挺不错的,现在分享给大家,也给大家做个参考。这篇文章主要为大家详细介绍了ASP.NET MVC5使用MiniPRofiler...
收集整理的这篇文章主要介绍了实例分析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性能的方法的详细内容,更多请关注其它相关文章!

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!

ASP.NETMiniProfiler

若转载请注明出处: 实例分析ASP.NET在MVC5中使用MiniProfiler监控MVC性能的方法
本文地址: https://pptw.com/jishu/592604.html
javascript object怎么转json 手把手教你使用工具切换 node 版本

游客 回复需填写必要信息