取得页面执行时间的代码
在Global.asax.cs文件中
protected void Application_BeginRequest(Object sender, EventArgs e)
{
Application["StartTime"] = System.DateTime.Now;
}
protected void Application_EndRequest(Object sender, EventArgs e)
{
System.DateTime startTime = (System.DateTime)Application["StartTime"];
System.DateTime endTime = System.DateTime.Now;
System.TimeSpan ts = endTime - startTime;
Response.Write("页面执行时间:"+ ts.Milliseconds +" 毫秒");
}
本文介绍了一种在ASP.NET应用程序中测量页面执行时间的方法。通过在Global.asax.cs文件中的Application_BeginRequest和Application_EndRequest事件中记录时间戳,可以计算出页面从开始请求到结束请求所需的总时间。
949

被折叠的 条评论
为什么被折叠?



