Cod*_*elp 15 asp.net-mvc mvc-mini-profiler
编辑 在这里得到答案
所以我想查看MiniProfiler来解决一些性能问题.在将其用于生产代码之前,我想尝试使用样本,然后继续创建MVC 5应用程序.这是使用模板创建的普通香草应用程序.
在HomeController的Index()方法中添加了此代码:
var profiler = MiniProfiler.Current;
using (profiler.Step("Set page title"))
{
ViewBag.Title = "Home Page";
}
using (profiler.Step("Doing complex stuff"))
{
using (profiler.Step("Step A"))
{ // something more interesting here
Thread.Sleep(100);
}
using (profiler.Step("Step B"))
{ // and here
Thread.Sleep(250);
}
}
return View();
Run Code Online (Sandbox Code Playgroud)
在_Layout中的jquery包下面添加了这一行:
@Scripts.Render("~/bundles/jquery")
@StackExchange.Profiling.MiniProfiler.RenderIncludes()
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
Run Code Online (Sandbox Code Playgroud)
跑了应用程序.什么都没有出现.没有剖析,没有.
我错过了什么?
问候.
Dig*_*Dan 29
这就是我必须要做的事情才能使MiniProfiler在我的ASP.NET MVC5项目中运行:
安装MiniProfiler和MiniProfiler.MVC4的NuGet包(该MVC4包支持MVC5)
Application_Start()
在Global.asax中添加以下内容:
protected void Application_Start()
{
...
// Setup profiler for Controllers via a Global ActionFilter
GlobalFilters.Filters.Add(new ProfilingActionFilter());
// initialize automatic view profiling
var copy = ViewEngines.Engines.ToList();
ViewEngines.Engines.Clear();
foreach (var item in copy)
{
ViewEngines.Engines.Add(new ProfilingViewEngine(item));
}
}
Run Code Online (Sandbox Code Playgroud)将以下内容添加到Global.asax中的"Application_BeginRequest()"和"Application_EndRequest()":
protected void Application_BeginRequest()
{
if (Request.IsLocal)
{
MiniProfiler.Start();
}
}
protected void Application_EndRequest()
{
MiniProfiler.Stop();
}
Run Code Online (Sandbox Code Playgroud)将以下内容添加到_Layout.cshtml(在</body>
标记之前):
...
@StackExchange.Profiling.MiniProfiler.RenderIncludes()
</body>
</html>
Run Code Online (Sandbox Code Playgroud)将以下内容添加到<handlers>
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>
Run Code Online (Sandbox Code Playgroud)这足以分析每个MVC控制器操作和视图.
在我的特定项目中,我使用的是Entity Framework 6,所以我也做了以下事情:
a)安装了MiniProfiler.EF6包
b)Application_Start()
在Global.asax 的末尾添加以下内容:
...
MiniProfilerEF6.Initialize();
}
Run Code Online (Sandbox Code Playgroud)
小智 5
你还要加电话:
MiniProfiler.Start();
Run Code Online (Sandbox Code Playgroud)
在Global.asax.cs到Application_BeginRequest事件中.
和:
MiniProfiler.Stop();
Run Code Online (Sandbox Code Playgroud)
在Global.asax.cs中为Application_EndRequest事件.
归档时间: |
|
查看次数: |
5544 次 |
最近记录: |