网页渲染时间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:
http://haacked.com/archive/2008/07/02/httpmodule-for-timing-requests.aspx