MiniProfiler项目实战精要

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/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

石头@很想你~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值