MiniProfiler, вероятно, в порядке, или вы можете зарегистрировать глобальный фильтр, подобный приведенному ниже коду.Очевидно стиль в соответствии с вашим сценарием (см. Часть response.Write (...) внизу).
Я не могу взять кредит на фильтр, потому что я нашел что-то почти идентичное в блоге (нехотя не помню где).
/// <summary>
/// Filter to display the execution time of both the action and result
/// </summary>
public class RequestTimingFilterAttribute : ActionFilterAttribute
{
/// <summary>
/// Returns a Stopwatch instance for the specific context to gather
/// diagnostics timing for
/// </summary>
/// <param name="context"></param>
/// <param name="name"></param>
/// <returns></returns>
private static Stopwatch GetTimer(ControllerContext context, string name)
{
var key = string.Format("__timer__{0}", name);
if (context.HttpContext.Items.Contains(key))
{
return (Stopwatch)context.HttpContext.Items[key];
}
var result = new Stopwatch();
context.HttpContext.Items[key] = result;
return result;
}
/// <summary>
/// Called before an action method executes.
/// </summary>
/// <param name = "filterContext">The filter context.</param>
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
GetTimer(filterContext, "action").Start();
}
/// <summary>
/// Called after the action method executes.
/// </summary>
/// <param name = "filterContext">The filter context.</param>
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
GetTimer(filterContext, "action").Stop();
}
/// <summary>
/// Called before an action result executes.
/// </summary>
/// <param name = "filterContext">The filter context.</param>
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
GetTimer(filterContext, "render").Start();
}
/// <summary>
/// Called after an action result executes.
/// </summary>
/// <param name = "filterContext">The filter context.</param>
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
var renderTimer = GetTimer(filterContext, "render");
renderTimer.Stop();
var actionTimer = GetTimer(filterContext, "action");
var response = filterContext.HttpContext.Response;
if (response.ContentType == "text/html")
{
response.Write(
string.Format(
"<div style='font-size: 70%; font-weight: bold; color: #888;'>Action '{0} :: {1}'<br /> Execute: {2}ms, Render: {3}ms.</div>",
filterContext.RouteData.Values["controller"],
filterContext.RouteData.Values["action"],
actionTimer.ElapsedMilliseconds,
renderTimer.ElapsedMilliseconds
)
);
}
}
}