asp.net显示页面执行时间

Global.asax需要添加的代码。利用我们了解当前页面的运行效率。
代码
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; 
Application[
"runtime"= (Convert.ToDouble((ts.Milliseconds)) / 1000); 


在要显示的地方: 页面执行时间:单位秒

 

<%=Convert.ToString(Application["runtime"]) %>

 


 

posted @ 2010-09-27 10:28  韩天伟  阅读(1378)  评论(0编辑  收藏  举报