国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net計算每個頁面執行時間的方法

2024-07-10 13:28:56
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了asp.net計算每個頁面執行時間的方法,涉及asp.net操作時間的相關技巧,非常具有實用價值,需要的朋友可以參考下

本文實例講述了asp.net計算每個頁面執行時間的方法。分享給大家供大家參考。具體分析如下:

這里的asp.net代碼可實現計算每個頁面的執行時間,無需要修改頁面的相關代碼,這段代碼會給所有的頁面統一加上執行時間顯示

 

 
  1. public class PerformanceMonitorModule : IHttpModule 
  2. public void Init(HttpApplication context) 
  3. context.PreRequestHandlerExecute += delegate(object sender,EventArgs e) 
  4. //Set Page Timer Star 
  5. HttpContext requestContext = ((HttpApplication)sender).Context; 
  6. Stopwatch timer = new Stopwatch(); 
  7. requestContext.Items["Timer"] = timer; 
  8. timer.Start(); 
  9. }; 
  10. context.PostRequestHandlerExecute += delegate(object sender, EventArgs e) 
  11. HttpContext httpContext = ((HttpApplication)sender).Context; 
  12. HttpResponse response = httpContext.Response; 
  13. Stopwatch timer = (Stopwatch)httpContext.Items["Timer"]; 
  14. timer.Stop(); 
  15. // Don't interfere with non-HTML responses 
  16. if (response.ContentType == "text/html"
  17. double seconds = (double)timer.ElapsedTicks / Stopwatch.Frequency; 
  18. string result_time = string.Format("{0:F4} sec ", seconds); 
  19. RenderQueriesToResponse(response,result_time); 
  20. }; 
  21. void RenderQueriesToResponse(HttpResponse response, string result_time) 
  22. response.Write("<div style=/"margin: 5px; background-color: #FFFF00/""); 
  23. response.Write(string.Format("<b>Page Generated in "+ result_time)); 
  24. response.Write("</div>"); 
  25. public void Dispose() { /* Not needed */ } 

希望本文所述對大家的asp.net程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 东乡县| 潼关县| 房产| 沾益县| 云安县| 开鲁县| 通州市| 阿克陶县| 乌兰浩特市| 巴中市| 隆尧县| 镇平县| 榆中县| 滨州市| 宜兰市| 佛学| 乌兰县| 曲麻莱县| 云龙县| 宁阳县| 玉山县| 双牌县| 新宾| 井研县| 慈利县| 上虞市| 石林| 清丰县| 大悟县| 勐海县| 沁源县| 邻水| 札达县| 讷河市| 磐石市| 贵溪市| 台江县| 桦川县| 福海县| 大田县| 皮山县|