MiniProfiler监控Asp.Net MVC5和EF性能
1. 安装依赖包
在web项目打开nuget包管理器搜索 MiniProfiler.Mvc5和MiniProfiler.EF6安装。
2. 在Global.asax中添加配置代码
protected void Application_Start()
{
MiniProfiler.Configure(new MiniProfilerOptions
{
// Sets up the route to use for MiniProfiler resources:
// Here, ~/profiler is used for things like /profiler/mini-profiler-includes.js
RouteBasePath = "~/profiler",
// Example of using SQLite storage instead
Storage = new SqliteMiniProfilerStorage(ConnectionString),
// Different RDBMS have different ways of declaring sql parameters - SQLite can understand inline sql parameters just fine.
// By default, sql parameters will be displayed.
//SqlFormatter = new StackExchange.Profiling.SqlFormatters.InlineFormatter(),
// These settings are optional and all have defaults, any matching setting specified in .RenderIncludes() will
// override the application-wide defaults specified here, for example if you had both:
// PopupRenderPosition = RenderPosition.Right;
// and in the page:
// @MiniProfiler.Current.RenderIncludes(position: RenderPosition.Left)
// ...then the position would be on the left on that page, and on the right (the application default) for anywhere that doesn't
// specified position in the .RenderIncludes() call.
PopupRenderPosition = RenderPosition.Right, // defaults to left
PopupMaxTracesToShow = 10, // defaults to 15
// ResultsAuthorize (optional - open to all by default):
// because profiler results can contain sensitive data (e.g. sql queries with parameter values displayed), we
// can define a function that will authorize clients to see the JSON or full page results.
// we use it on http://stackoverflow.com to check that the request cookies belong to a valid developer.
ResultsAuthorize = request => request.IsLocal,
// ResultsListAuthorize (optional - open to all by default)
// the list of all sessions in the store is restricted by default, you must return true to allow it
ResultsListAuthorize = request =>
{
// you may implement this if you need to restrict visibility of profiling lists on a per request basis
return true; // all requests are legit in this example
},
// Stack trace settings
StackMaxLength = 256, // default is 120 characters
// (Optional) You can disable "Connection Open()", "Connection Close()" (and async variant) tracking.
// (defaults to true, and connection opening/closing is tracked)
TrackConnectionOpenClose = true
}
// Optional settings to control the stack trace output in the details pane, examples:
.ExcludeType("SessionFactory") // Ignore any class with the name of SessionFactory)
.ExcludeAssembly("NHibernate") // Ignore any assembly named NHibernate
.ExcludeMethod("Flush") // Ignore any method with the name of Flush
.AddViewProfiling() // Add MVC view profiling (you want this)
// If using EntityFrameworkCore, here's where it'd go.
// .AddEntityFramework() // Extension method in the MiniProfiler.EntityFrameworkCore package
);
// If we're using EntityFramework 6, here's where it'd go.
// This is in the MiniProfiler.EF6 NuGet package.
// MiniProfilerEF6.Initialize();
}
protected void Application_BeginRequest()
{
// You can decide whether to profile here, or it can be done in ActionFilters, etc.
// We're doing it here so profiling happens ASAP to account for as much time as possible.
if (Request.IsLocal) // Example of conditional profiling, you could just call MiniProfiler.StartNew();
{
MiniProfiler.StartNew();
}
}
protected void Application_EndRequest()
{
MiniProfiler.Current?.Stop(); // Be sure to stop the profiler!
}
3. 在web.config中添加js配置

<add name="MiniProfiler" path="profiler/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
也可以使用以下方式添加所有需要的js
<modules runAllManagedModulesForAllRequests="true" />
<!--<handlers>
<add name="MiniProfiler" path="profiler/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
</handlers>-->
4. 在需要的页面添加显示监控代码(所有页面可以在layout.cshtml中添加)
4.1 添加命名空间
@using StackExchange.Profiling;
4.2 在body块最后添加显示代码
@MiniProfiler.Current.RenderIncludes(position: RenderPosition.Right, showTrivial: false, showTimeWithChildren: true)
MiniProfiler监控Asp.Net MVC5和EF性能的更多相关文章
- 使用MiniProfiler调试ASP.NET web api项目性能
本质上,集成Miniprofiler可以分解为三个问题: 怎样监测一个WebApi项目的性能. 将性能分析监测信息从后端发送到UI. 在UI显示分析监测结果. 首先安装Miniprofiler,Min ...
- ASP.NET MVC5利用EF,反向自动生成数据库
1.在Model类里面,写好相应的属性. using System; using System.Collections.Generic; using System.Linq; using System ...
- 实例分析ASP.NET在MVC5中使用MiniProfiler监控MVC性能的方法
这篇文章主要为大家详细介绍了ASP.NET MVC5使用MiniProfiler监控MVC性能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 MiniProfiler ,一个简单而有效的迷你剖析器 ...
- 转:asp.net mvc ef 性能监控调试工具 MiniProfiler
MiniProfiler官网:http://miniprofiler.com/ MiniProfiler的一个特别有用的功能是它与数据库框架的集成.除了.NET原生的 DbConnection类,Mi ...
- MiniProfiler监控调试MVC5以及EntityFramework6性能
想要通过在MVC中view中直观的查看页面加载以及后台EF执行情况,可以通过MiniProfiler小工具来实现. 但是从网上搜索的相关信息要么是MVC4下的老版本的MiniProfiler,要么就是 ...
- 使用MiniProfiler调试ASP.NET MVC网站性能
MiniProfiler 以前开发Webform的时候可以开启trace来跟踪页面事件,这对于诊断程序的性能是有很大的帮助的,起到事半功倍的作用,今天我就来谈用mvc开 发项目的调试和性能监控.EF框 ...
- Miniprofiler 监控ef执行详解
首先NuGet添加 相对应ef版本的Miniprofiler.ef引用 web.config文件中添加 <system.webServer> <handlers> <a ...
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(1)-前言与目录(持续更新中...)
开发工具:VS2015(2012以上)+SQL2008R2以上数据库 您可以有偿获取一份最新源码联系QQ:729994997 价格 666RMB 升级后界面效果如下: 任务调度系统界面 http: ...
- 构建ASP.NET MVC5+EF6+EasyUI 1.4.3+Unity4.x注入的后台管理系统
开篇:从50开始系统已经由MVC4+EF5+UNITY2.X+Quartz 2.0+easyui 1.3.4无缝接入 MVC5+EF6+Unity4.x+Quartz 2.3 +easyui 1.4. ...
随机推荐
- 单机MongoD搭建
MongoD 安装 1 .下载地址: wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.6.8.tgz 2 .添加 ...
- P1113 杂务 拓扑排序
题目描述 John的农场在给奶牛挤奶前有很多杂务要完成,每一项杂务都需要一定的时间来完成它.比如:他们要将奶牛集合起来,将他们赶进牛棚,为奶牛清洗乳房以及一些其它工作.尽早将所有杂务完成是必要的,因为 ...
- js初学练手:Csdn Ads Cleaner
最新版本在这里哒:https://greasyfork.org/zh-CN/scripts/376621-csdn-ads-cleaner 隔壁csdn的广告太猖獗啦!写个js管管它 需配合Tempe ...
- Python爬虫开发与项目实战
Python爬虫开发与项目实战(高清版)PDF 百度网盘 链接:https://pan.baidu.com/s/1MFexF6S4No_FtC5U2GCKqQ 提取码:gtz1 复制这段内容后打开百度 ...
- JTAG各类接口针脚定义及含义
注:转自 揽月阁 JTAG有10pin的.14pin的和20pin的,尽管引脚数和引脚的排列顺序不同,但是其中有一些引脚是一样的,各个引脚的定义如下. 一.引脚定义 Test Clock Input ...
- Day3----《Pattern Recognition and Machine Learning》Christopher M. Bishop
其实今天只花了一点点时间来学习这本书, 如果模型的参数过多,而训练数据又不足够多的话,就会出现overfitting. overfitting可以通过regularization来解决,贝叶斯方法也可 ...
- System.InvalidOperationException: 支持“XXX”上下文的模型已在数据库创建后发生更改。请考虑使用 Code First 迁移更新数据库(http://go.microsoft.com/fwlink/?LinkId=238269)。
System.InvalidOperationException: 支持“XXX”上下文的模型已在数据库创建后发生更改.请考虑使用 Code First 迁移更新数据库(http://go.micro ...
- 【安全性测试】解决关于appscan基于登录会话检测失败问题
有些问题久了忽然就想通怎么解决了,很神奇.这次要说的是,关于appscan无法检测到会话的问题,因为在百度上一直找不到相关的解决方法,这个问题困扰了我很久,今天终于找到方法解决了! 日常配置扫描内容: ...
- python学习:元组和嵌套
tuple(元组):只是可读,不可以修改# tup1 = () #空元组# tup2 = (20,) #元组内有一个元素,需要在元素后添加逗号 a = (1,2,3,4)print(a[1])a[1] ...
- LeetCode笔记:140. Word Break II
题目描述 给定一个非空的字符串s,一个非空的字符串list作为字典.通过在s中添加空格可以将s变为由list中的word表示的句子,要求返回所有可能组成的句子.设定list中的word不重复,且每一个 ...