您的位置:首页 > 其它

如何判断一个页面加载所耗费的时间【引用】

2009-03-29 16:10 316 查看
C# code

public class UrlReWrite : IHttpModule
{
private DateTime start;
private DateTime end;
public UrlReWrite()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
#region IHttpModule 成员
public void Dispose()
{
throw new Exception("The method or operation is not implemented.");
}
public void Init(HttpApplication context)
{
context.BeginRequest += new EventHandler(Begin_Request);
context.EndRequest += new EventHandler(End_Request);
}
#endregion
private void Begin_Request(object sender, EventArgs e)
{
start = DateTime.Now;
//HttpApplication app = sender as HttpApplication;
//string currentUrl = app.Context.Request.RawUrl;
//string newUrl = Common.GeneratePhysical(currentUrl);
//app.Context.RewritePath(newUrl);
}
private void End_Request(object sender, EventArgs e)
{
HttpApplication app = sender as HttpApplication;
end = DateTime.Now;
TimeSpan t = end - start;
app.Context.Response.Write(string.Format("<!-- Server:{0} now:{1} exec time: {2}-->", app.Context.Server.MachineName,DateTime.Now, t));
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: