前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用性能优化工具 MVC Mini Profiler (MVC3+EF4.1)

使用性能优化工具 MVC Mini Profiler (MVC3+EF4.1)

作者头像
Isaac Zhang
发布2019-09-10 18:39:57
3570
发布2019-09-10 18:39:57
举报
文章被收录于专栏:奔跑的人生奔跑的人生

安装: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中的使用

代码语言:javascript
复制
View Code 
 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

6,Global文件中

代码语言:javascript
复制
View Code 
 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

7,结果

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2012-04-28 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档