62,074
社区成员
发帖
与我相关
我的任务
分享
protected void Application_BeginRequest(Object sender, EventArgs e)
{
Context.Items["BeginRequestTickCount"] = GetTime.GetTickCount();
}
public static string WriteTime(HttpContext context)
{
StringBuilder htmlEnd = new StringBuilder();//用于存放html
htmlEnd.AppendLine("<script type=\"text/javascript\">LoadTime(" + context.Items["EndRequestTickCount"].ToString() + ",\"" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\");</script>");//加入载入时间的javascript事件
htmlEnd.AppendLine("</body>"); //加入从母板页中删除的html
htmlEnd.AppendLine("</html>");//加入从母板页中删除的html
//Response.Write(htmlEnd.ToString());//输出html
//htmlEnd.Remove(0, htmlEnd.Length - 1);//清空html
return htmlEnd.ToString();
}
protected void Application_EndRequest(Object sender, EventArgs e)
{
long EndRequestTickCount = (long)Context.Items["BeginRequestTickCount"];
TimeSpan ts = new TimeSpan(MvcApplication2.Models.GetTime.GetTickCount() - EndRequestTickCount);
double ot = ts.TotalMilliseconds / 1000;
Context.Items["EndRequestTickCount"] = ot.ToString();
Response.WriteSubstitution(new HttpResponseSubstitutionCallback(WriteTime));
Context.Items["EndRequestTickCount"] = null;
Context.Items["BeginRequestTickCount"] = null;
}
<script type="text/javascript">
function LoadTime(stime, snow) {
document.getElementById("loadTime").innerHTML = "Processed in " + stime + " second(s), 0 Queries. GMT+8, " + snow;
}
</script>
<div id="loadTime">
</div>