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


本文摘自PHP中文网,作者巴扎黑,侵删。

这篇文章主要为大家详细介绍了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中


1

2

3

4

5

6

7

8

9

10

11

12

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中


1

2

3

4

5

6

7

8

9

10

11

12

protected void Application_BeginRequest()

{

 if (Request.IsLocal)

 {

  MiniProfiler.Start();

 }

}

 

protected void Application_EndRequest()

{

 MiniProfiler.Stop();

}

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


1

2

3

@StackExchange.Profiling.MiniProfiler.RenderIncludes()

</body>

</html>

5.将以下内容添加到<handlers>Web.config 的部分中


1

2

3

4

5

6

7

8

9

10

<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性能的方法的详细内容!

相关阅读 >>

分享19个asp脚本语言的基本技巧

asp.net mvc实现404跳转的代码实例

关于core mvc压缩样式的实例详解(asp)

《asp.net》数据绑定―datalist实践篇的图文代码详解

asp.net操作日期常用代码

asp.net中session失效是怎么解决的?

极客学院asp.net视频教程的资料推荐

asp.net core实例详解四(project.json文件)

.net mvc从视图传参到控制器的3种形式

详细介绍《asp.net》数据绑定――gridview

更多相关阅读请进入《MiniProfiler》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...