Miniprofiler 监控ef执行详解

首先NuGet添加 相对应ef版本的Miniprofiler.ef引用

 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 文件中添加

protected void Application_Start(object sender, EventArgs e)
{

StackExchange.Profiling.EntityFramework6.MiniProfilerEF6.Initialize();

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

在需要监控的webfrom页面中增加

protected override void OnPreRender(EventArgs e)
{
Response.Write(StackExchange.Profiling.MiniProfiler.RenderIncludes());
base.OnPreRender(e);
}

运行页面

点击share 查看详细信息

以上就是MiniProfiler 监控webfrom中使用ef操作过程。

鹰击长空,鱼翔浅底
原文地址:https://www.cnblogs.com/farmer-y/p/5895352.html