使用MiniProfiler调试Asp.net Mvc性能

本文详细介绍了如何利用NuGet包管理器添加MiniProfiler.EF组件到MVC5应用中,并在关键Action处进行性能监控。通过在Global文件中初始化MiniProfiler,在_Layout文件中引入渲染脚本,以及在webconfig文件中配置路由处理,实现了对应用性能的细微监控。实例展示了如何在Action中使用MiniProfiler来记录数据库操作的时间,有效提高了开发效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. 使用nuget添加MiniProfiler.EF组件
    图片

  2. 在Global文件中配置MiniProfiler

     protected void Application_Start()
     {
         AreaRegistration.RegisterAllAreas();
         FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
         RouteConfig.RegisterRoutes(RouteTable.Routes);
         BundleConfig.RegisterBundles(BundleTable.Bundles);
    
         //初始化miniProfiler
         StackExchange.Profiling.EntityFramework6.MiniProfilerEF6.Initialize();
     }
    
     protected void Application_BeginRequest()
     {
         MiniProfiler.Start();
     }
    
     protected void Application_EndRequest()
     {
         MiniProfiler.Stop();
     }
  3. 在_Layout文件中添加

     @StackExchange.Profiling.MiniProfiler.RenderIncludes()
  4. 在webconfig文件中添加

     <system.webServer>
         <handlers>
             <add name="MiniProfiler" path="mini-profiler-resources/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
         </handlers>
     </system.webServer>
  5. 查看运行结果
    图片

6.细微监控,在Action如下添加:

var profiler = MiniProfiler.Current;
List<PictureCategory> cates;
using (profiler.Step("获取PictureCategory列表"))
{
    cates = db.PictureCategories.ToList();
}

关于如何使用MiniProfiler更好的文章MiniProfiler.EF6监控调试MVC5和EF6的性能

转载于:https://www.cnblogs.com/dongshuangjie/p/5175500.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值