Page Render Time in MVC

后端 未结 4 561
误落风尘
误落风尘 2021-02-06 05:45

Q: How do I calculate the total time it takes to render an MVC page and display the time on the master page.

In Asp.net Web Form I created a Base page class like so:

4条回答
  •  逝去的感伤
    2021-02-06 06:25

    I would probably override the OnActionExecuting and OnActionExecuted methods on the Controller class.

    public class BaseController : Controller {
        // Called before the action is executed
        public override void OnActionExecuting(ActionExecutingContext ctx) {
            base.OnActionExecuting(ctx);
            // Start timing
        }
    
        // Called after the action is executed
        public override void OnActionExecuted(ActionExecutedContext ctx) {
            base.OnActionExecuted(ctx);
            // Stop timing
        }
    }
    

提交回复
热议问题