zoukankan      html  css  js  c++  java
  • 使用性能优化工具 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中的使用

     

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

     

    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,结果


  • 相关阅读:
    VBA实现任意n阶幻方的一种填法(n≥3)
    业余兼职的全行业薪酬对照(发表者: swf11519 )
    在VBA中获取“我的文档”的目录路径
    应用API函数在用户窗体中画圆
    双色球历史数据
    一沙一世界(10亿光年),科学的图文介绍
    四阶素数幻方问题
    Android_左右滑动切换背景
    深圳中软实习始末
    Android系统Surface机制的SurfaceFlinger服务的启动过程分析
  • 原文地址:https://www.cnblogs.com/zhangpan1244/p/2474792.html
Copyright © 2011-2022 走看看