通常来说,PHP 或其他 Web 框架获取总响应时间很容易,只需在文件顶部启动计时器并在文件末尾停止即可。
在 ASP.Net 中,有整个页面生命周期,所以我不知道如何做到这一点。我希望此响应时间记录发生在母版页中,并且响应时间显示在页面的页脚中。这样做的最好方法是什么? ASP.Net 中有内置的东西吗?是否有可能包括 OnRender 时间?
你可以在 Global.asax 上完成,看看这个article http://www.thejoyofcode.com/Time_taken_to_render_a_page_in_ASP.NET.aspx
void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Items["renderStartTime"] = DateTime.Now;
}
void Application_EndRequest(object sender, EventArgs e)
{
DateTime start = (DateTime) HttpContext.Current.Items["renderStartTime"];
TimeSpan renderTime = DateTime.Now - start;
HttpContext.Current.Response.Write("<!-- Render Time: " + renderTime + " -->");
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)