[英]MiniProfiler not showing up on asp.net MVC
我把它添加到我的Global.asax.cs:
protected void Application_BeginRequest()
{
if (Request.IsLocal)
{
MiniProfiler.Start();
}
}
protected void Application_EndRequest()
{
MiniProfiler.Stop();
}
我补充道
@MiniProfiler.RenderIncludes()
就在_Layout.cshtml中的</body>
标记下方。
在我的控制器中我正在使用:
public class HomeController : Controller
{
public ActionResult Index()
{
var profiler = MiniProfiler.Current; // it's ok if this is null
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("~/Views/Home/Index.cshtml");
}
}
但我的页面上没有显示任何内容,也没有任何配置文件框。
在查看源代码时我只看到这个:
<script async type="text/javascript" id="mini-profiler" src="/mini-profiler-resources/includes.js?v=xwYPDDH1blvqmxgsBweNC++H7CFU3KGQ+zFcVlJPsXw=" data-version="xwYPDDH1blvqmxgsBweNC++H7CFU3KGQ+zFcVlJPsXw=" data-path="/mini-profiler-resources/" data-current-id="6d24704e-3003-44f8-9965-437c6275d639" data-ids="8ec2c718-4375-4d3f-9b69-4092e534143e,6d24704e-3003-44f8-9965-437c6275d639" data-position="left" data-trivial="false" data-children="false" data-max-traces="15" data-controls="false" data-authorized="true" data-toggle-shortcut="Alt+P" data-start-hidden="false"></script>
在您的web.config中,添加以下内容:
<system.webServer>
...
<handlers>
<add name="MiniProfiler" path="mini-profiler-resources/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
...
</handlers>
...
如果您想要一些甜蜜的MVC Action分析(与您的问题无关),请将此行添加到Global.asax.cs中的Application_Start
:
GlobalFilters.Filters.Add(new StackExchange.Profiling.MVCHelpers.ProfilingActionFilter());
如果有人尝试过Alden的解决方案并且仍然无法为您工作,请尝试将willardrostt建议的discardResults设置为false
// Global.asax.cs file
protected void Application_BeginRequest()
{
if (Request.IsLocal)
{
MiniProfiler.Start();
}
}
protected void Application_EndRequest(object sender, EventArgs e)
{
MiniProfiler.Stop(discardResults: false);
}
在MiniProfiler最新版本:4.0.165。 确保在Application_Start()中添加了代码
protected void Application_Start()
{
...
MiniProfiler.Configure(new MiniProfilerOptions());//default setting
MiniProfilerEF6.Initialize();
}
Doc在这里: https : //miniprofiler.com/dotnet/AspDotNet
在最新版本中,您不需要添加
<system.webServer>
...
<handlers>
<add name="MiniProfiler" path="mini-profiler-resources/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
...
</handlers>
...
在Web.config中了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.