EF框架 监控小工具 MiniProfiler

一、NuGet安装:

MiniProfiler

MiniProfiler.EF6

如果在MVC中使用则再多安装

MiniProfiler.MVC(X)       //X:mvc版本号

二、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>

三、Global.asax.cs

protected void Application_Start(object sender, EventArgs e)
        {
            // 在应用程序启动时运行的代码  ※必须要放置在数据库初始化前
            MiniProfilerEF6.Initialize();
            // 数据库初始化
            Database.SetInitializer<DataBaseCenter.DB.BIContext>(null);           

        }
    protected void Application_BeginRequest(object sender, EventArgs e)
        {
            if (Request.IsLocal) MiniProfiler.Start();
        }
    protected void Application_EndRequest()
        {
            if (Request.IsLocal) MiniProfiler.Stop();
        }

页面呈现:在body中添加

<%= Request.IsLocal ? StackExchange.Profiling.MiniProfiler.RenderIncludes().ToString() :"" %>

呈现结果:

这样就可以实地检测喽。

posted @ 2016-10-14 10:51  鞍山老菜鸟  阅读(353)  评论(0编辑  收藏  举报