网页渲染时间MVC [英] Page Render Time in MVC

查看:139
本文介绍了网页渲染时间MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问:我如何计算总花费的时间来呈现一个MVC页面,并显示在主网页上的时间

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

在Asp.net Web窗体我创建了一个基本页类,像这样:

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

public class PageBase : System.Web.UI.Page
{      
    private DateTime startTime = DateTime.Now;
    private TimeSpan renderTime;   
    public DateTime StartTime
    {
        set { startTime = value; }
        get { return startTime; }
    }  
    public virtual string PageRenderTime
    {
        get
        {
            renderTime = DateTime.Now - startTime;
            return renderTime.Seconds + "." + renderTime.Milliseconds + " seconds";
        }
    }       
}

我然后调用该方法在我的母版页,像这样:

I would then call the method on my Master Page like so:

<div id="performance">
     <% =PageRenderTime %>
</div>

问:我如何完成同样的事情与MVC框架

Q: How do I accomplish the same thing with the MVC Framework?

问:MVC框架我在哪里设置开始时间第一次创建页面时?

Q: With the MVC framework where do I set the start time when a page is first created?

推荐答案

要做到这一点是计算请求时序..开始请求和结束请求的最佳途径....
看看这个伟大的职位:

The best way to do this is calculate the request timing .. Begin Request and End Request .... Check out this great post:

<一个href=\"http://haacked.com/archive/2008/07/02/httpmodule-for-timing-requests.aspx\">http://haacked.com/archive/2008/07/02/httpmodule-for-timing-requests.aspx

这篇关于网页渲染时间MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆