对每个操作调用使用 MVC Miniprofiler
我一直在尝试 Mvc MiniProfiler 这个出色的工具。
我不想在我的所有视图中添加大量 Step
命令,因此我希望在每个操作调用中都使用探查器。坏主意?这是我到目前为止所尝试过的:
public abstract class BaseController : Controller
{
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
var profiler = MiniProfiler.Current;
using (profiler.Step("Action: "+filterContext.ActionDescriptor.ActionName))
{
base.OnActionExecuting(filterContext);
}
}
}
但我认为这没有达到我的目的?我想我需要在 OnActionExecuting
上启动探查器,并在 OnResultExecuted
上停止它。考虑到探查器设计为与 using
语句一起使用,我该如何执行此操作。
Iv been experimenting the great tool, Mvc MiniProfiler.
I don't want to litter all my view with lots of Step
commands, so I am wanting to use the profiler with every action call. Bad idea? This is what I have tried so far:
public abstract class BaseController : Controller
{
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
var profiler = MiniProfiler.Current;
using (profiler.Step("Action: "+filterContext.ActionDescriptor.ActionName))
{
base.OnActionExecuting(filterContext);
}
}
}
But I don't think this is doing what I am intending? I think I need to start the profiler on OnActionExecuting
and stop it on OnResultExecuted
. How do I do this, considering the profiler is designed to be used with the using
statement.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以定义一个全局操作过滤器:
并在 Global.asax 中注册:
这几乎就是全部。
You could define a global action filter:
and register in
Global.asax
:and that's pretty much all.
思考并使用ActionFilter就可以了。但 MVC 仍然是一个 ASP .NET 应用程序。要在每个请求开始和结束时启动和停止 MiniProfiler,您可以尝试 Global.asax.cs 文件中的应用程序事件。
It is alright to think and use ActionFilter. But MVC is still an ASP .NET application. To start and stop MiniProfiler at beginning and ending of each request, you can try the application events in Global.asax.cs file.