NuGet安装
1,MiniProfiler核心(版本3.2)
2,MiniProfiler.EF(版本3.0.11,根据使用的EF版本选择4.5.6)
3,MiniProfiler.MVC(选择MVC4,版本3.0.11)
配置
1,Global.asax文件中添加
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
//增对特定权限用户才开放监控功能
MiniProfiler.Settings.Results_Authorize = Request =>
{
string name = Request.Cookies["name"] == null ? "" : Request.Cookies["name"].Value;
if (name.Equals("admin"))
return true;
else
return false;
};
//监控EF
MiniProfilerEF6.Initialize();
//MVC视图监测
GlobalFilters.Filters.Add(new ProfilingActionFilter());
var copy = ViewEngines.Engines.ToList();
ViewEngines.Engines.Clear();
foreach (var item in copy)
{
ViewEngines.Engines.Add(new ProfilingViewEngine(item));
}
}
//EF监测
protected void Application_BeginRequest()
{
if (Request.IsLocal)
{
MiniProfiler.Start();
}
}
//EF监测
protected void Application_EndRequest()
{
MiniProfiler.Stop();
}
}
2,要监控的html中添加
@using StackExchange.Profiling;
@MiniProfiler.RenderIncludes();
3,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>
如安装错版本
1,卸载packbag
2,清除引用
3,清除bin内残留dll
4,清除packbag内残留包
5,在项目文件目录中搜索该packbag名称,查看并卸载较高的那个文件版本
前端效果展示如下:
针对性监控:在监控条目较多的时候使用,使得特定监控更佳清晰可见;也可对方法等一系列行为进行性能监测,包括ajax等等
using (MiniProfiler.Current.Step("针对性监控-增加数据测试1"))
{
db.Dep.Add(new Dep() { depName = "信息中心1", id = "27" });
db.SaveChanges();
}
using (MiniProfiler.Current.Step("针对性监控-增加数据测试2"))
{
db.Dep.Add(new Dep() { depName = "信息中心1", id = "28" });
db.SaveChanges();
}
效果
其他详细文档见官网地址:https://miniprofiler.com/dotnet/