统计asp.net页面访问时间
2010-04-30 14:31
387 查看
在做项目的performance问题时候,为了方便跟踪各个页面的postback或者callback的花费时间,写了一个简单的httpmodule,用来打印访问花费时间。
使用的时候将下边这个类编译成一个dll,在web.config里配置好,再打开debugview就可以了。
配置
<httpModules>
<clear />
<add name="TracingModule" type="PerformanceTracing.TracingModule,PerformanceTracing"/>
.....
</httpModules>
代码
代码
使用的时候将下边这个类编译成一个dll,在web.config里配置好,再打开debugview就可以了。
配置
<httpModules>
<clear />
<add name="TracingModule" type="PerformanceTracing.TracingModule,PerformanceTracing"/>
.....
</httpModules>
代码
代码
using System; using System.Collections.Generic; using System.Text; using System.Web; using System.Diagnostics; namespace PerformanceTracing { public class TracingModule : IHttpModule { #region IHttpModule Members public void Dispose() { } public void Init(HttpApplication context) { context.BeginRequest += new EventHandler(context_BeginRequest); context.EndRequest += new EventHandler(context_EndRequest); } private string getFilePath(object sender) { string strPath = (((HttpApplication)sender)).Request.FilePath; if (strPath != null && strPath.EndsWith("aspx")) { return strPath.Substring(strPath.LastIndexOf("/")); } return string.Empty; } void context_EndRequest(object sender, EventArgs e) { string fileName = getFilePath(sender); if (fileName.EndsWith("aspx")) { Stopwatch perfmonWatch = HttpContext.Current.Items["Stopwatch"] as Stopwatch; if (perfmonWatch != null) { perfmonWatch.Stop(); string msg = "Page name: " + fileName + ". The total response time: " + perfmonWatch.Elapsed.TotalSeconds + "s. IsCallBack: " + (HttpContext.Current.Request.Form["__CALLBACKPARAM"] != null).ToString(); Trace.Write(msg); } } } void context_BeginRequest(object sender, EventArgs e) { if ((((HttpApplication)sender)).Request.FilePath.EndsWith("aspx")) { Stopwatch perfmonWatch = new Stopwatch(); HttpContext.Current.Items["Stopwatch"] = perfmonWatch; perfmonWatch.Start(); } } #endregion } }
相关文章推荐
- 在Asp.Net MVC中实现计算页面执行时间及简单流量统计
- 在Asp.Net MVC中实现计算页面执行时间及简单流量统计
- asp.net 访问页面访问统计实现
- asp.net 访问页面访问统计实现 for iis7
- 在IIS中访问APS页面时提示:“最可能的原因使用的托管的处理程序,但是未安装或未完整安装asp.net“
- [ASP.NET]Asp.net取得页面执行时间的代码
- Asp.net中Web.config 页面访问按角色授权配置
- asp.net页面加载时间计算
- 静态页面浏览数统计 for asp.net
- ASP.NET 拒绝未验证的用户任意访问每个页面
- 页面间隔半秒钟更新时间 Asp.net使用Comet开发http长连接示例分享
- 设置ASP.NET页面的运行超时时间详细到单个页面及站点
- 网站今日访问,总访问及在线人数统计 asp.net
- Asp.net有关访问页面权限的限制和错误页面配置
- asp.net页面加载时间计算方案
- asp.net页面统计报表的实现
- 访问asp.net页面时Server Application Unavailable
- 在HTML页面中实现点击数统计 For ASP.Net版! (接近正解)
- 在IIS中访问APS页面时提示:“最可能的原因使用的托管的处理程序,但是未安装或未完整安装asp.net“
- ASP.net页面访问顺序