使用性能优化工具 MVC Mini Profiler (MVC3+EF4.1)
安装:1,
2,运行命令 PM> Install-Package MiniProfiler
3,因为我这里使用的是Entity framework 4.1 code first 所以还需要下载 一个包PM> Install-Package MiniProfiler.EF
4,使用说明,查看连接:
http://miniprofiler.com/
5,我在MVC3+E.F4.1中的使用

1 public ActionResult Index(int pindex = 0)
2 {
3 try
4 {
5 var profiler = MiniProfiler.Current; // it's ok if this is null
6 using (profiler.Step("Test Bless page"))
7 { // something more interesting here
8 ViewBag.BlessMessageList = GetBlessingStr(pindex);
9 Thread.Sleep(100);
10
11 }
12 }
13 catch (Exception ex)
14 {
15 #region 操作失败发送邮件给管理员
16 EmailServer send = new EmailServer();
17 string body = "祭奠在线网站祈福墙出现错误,错误信息: " + ex.Message;
18 //这个是附件列表
19 List<string> list = new List<string>();
20 string reciveMail = StringHelper.GetReceiveMail();
21 string CcEmailList = StringHelper.GetCCMailList();
22 send.Send(reciveMail, "", CcEmailList, "祭奠在线网站报错邮件", body, list);
23 #endregion
24 //并记录错误日志
25 Log.WriteLog("网站祈福墙信息", "/Log/Blessing/", ex.Message);
26 //strJson = "系统正在升级,请稍候再试!";
27 }
28 return View();
29
2 {
3 try
4 {
5 var profiler = MiniProfiler.Current; // it's ok if this is null
6 using (profiler.Step("Test Bless page"))
7 { // something more interesting here
8 ViewBag.BlessMessageList = GetBlessingStr(pindex);
9 Thread.Sleep(100);
10
11 }
12 }
13 catch (Exception ex)
14 {
15 #region 操作失败发送邮件给管理员
16 EmailServer send = new EmailServer();
17 string body = "祭奠在线网站祈福墙出现错误,错误信息: " + ex.Message;
18 //这个是附件列表
19 List<string> list = new List<string>();
20 string reciveMail = StringHelper.GetReceiveMail();
21 string CcEmailList = StringHelper.GetCCMailList();
22 send.Send(reciveMail, "", CcEmailList, "祭奠在线网站报错邮件", body, list);
23 #endregion
24 //并记录错误日志
25 Log.WriteLog("网站祈福墙信息", "/Log/Blessing/", ex.Message);
26 //strJson = "系统正在升级,请稍候再试!";
27 }
28 return View();
29
6,Global文件中

1 protected void Application_Start()
2 {
3 AreaRegistration.RegisterAllAreas();
4
5 RegisterGlobalFilters(GlobalFilters.Filters);
6 RegisterRoutes(RouteTable.Routes);
7 //启动性能调试工具---Created by isaac on 2012-04-28
8 //Note, that EF 4.1 Update 1 (the version currently on NuGet) has a breaking change which throws the following error when specifying a connection string:
9 //The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
10 //MiniProfiler attempts to resolve this issue by detecting the version of Entity Framework that it is running against. If this doesn't work (due to security exceptions), force the hack to be applied by replacing the Initialize() call with:
11
12 //MiniProfilerEF.Initialize_EF42(); // in Application_Start
13 MiniProfilerEF.Initialize(); //调用EF-CODE FIRST要下载包Install-Package MiniProfiler.EF
14
15 }
16 protected void Application_BeginRequest()
17 {
18 //判断是否是本地操作
19 if (Request.IsLocal)
20 {
21 MiniProfiler.Start();
22 }
23 }
24 protected void Application_EndRequest()
25 {
26 //停止性能工具
27 MiniProfiler.Stop();
28
2 {
3 AreaRegistration.RegisterAllAreas();
4
5 RegisterGlobalFilters(GlobalFilters.Filters);
6 RegisterRoutes(RouteTable.Routes);
7 //启动性能调试工具---Created by isaac on 2012-04-28
8 //Note, that EF 4.1 Update 1 (the version currently on NuGet) has a breaking change which throws the following error when specifying a connection string:
9 //The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
10 //MiniProfiler attempts to resolve this issue by detecting the version of Entity Framework that it is running against. If this doesn't work (due to security exceptions), force the hack to be applied by replacing the Initialize() call with:
11
12 //MiniProfilerEF.Initialize_EF42(); // in Application_Start
13 MiniProfilerEF.Initialize(); //调用EF-CODE FIRST要下载包Install-Package MiniProfiler.EF
14
15 }
16 protected void Application_BeginRequest()
17 {
18 //判断是否是本地操作
19 if (Request.IsLocal)
20 {
21 MiniProfiler.Start();
22 }
23 }
24 protected void Application_EndRequest()
25 {
26 //停止性能工具
27 MiniProfiler.Stop();
28
7,结果
在编程的道路上,一往无前,埋头狂奔。
[奔跑的人生] | [segmentfault] | [spring4all] | [csdn] | [掘金] | [OSChina] | [简书] | [知乎] | [51CTO]
[奔跑的人生] | [segmentfault] | [spring4all] | [csdn] | [掘金] | [OSChina] | [简书] | [知乎] | [51CTO]
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?