使用MiniProfiler调试ASP.NET web api项目性能

本质上,集成Miniprofiler可以分解为三个问题:

  1. 怎样监测一个WebApi项目的性能。
  2. 将性能分析监测信息从后端发送到UI。
  3. 在UI显示分析监测结果。

首先安装Miniprofiler,MiniProfiler.EF6

在Global.asax  加入

 1 protected override void Application_Start(object sender, EventArgs e)
 2 {
 3 StackExchange.Profiling.EntityFramework6.MiniProfilerEF6.Initialize();
 4 MiniProfiler.Settings.Results_Authorize = p => true;
 5 MiniProfiler.Settings.Results_List_Authorize = p => true;
 6 MiniProfiler.Settings.RouteBasePath = "~/profiler/";//访问路径/profiler/results 或者/profiler/results-index
 7 
 8 base.Application_Start(sender, e);
 9 }
10 
11 
12 protected void Application_BeginRequest()
13 {
14 
15 MiniProfiler.Start();
16 
17 }
18 
19 protected void Application_EndRequest()
20 {
21 MiniProfiler.Stop();
22 }

运行项目,http://localhost//profiler/results-index  即可看到监测结果

原文地址:https://www.cnblogs.com/lyl6796910/p/9675046.html