获取aspx页面执行时间完全解决方案

来源:百度文库 编辑:神马文学网 时间:2024/05/06 14:57:23
经过一段时间的摸索,终于找到了一个完全解决方案:
1.在工程中添加一个类,就叫做PageElapse.cs
代码如下(微软PM&A2K讲座的范例代码):
using System;
using System.Web;
namespace Common
{
///
/// PageElapse 的摘要说明。
///

public class PageElapse : IHttpModule
{
private DateTime _StartTime;
public void Init(System.Web.HttpApplication context)
{
context.BeginRequest += new EventHandler(OnBeginRequest);
context.EndRequest += new EventHandler(OnEndRequest);
}
public void Dispose()
{
}
private void OnBeginRequest(object sender, EventArgs e)
{
_StartTime = DateTime.Now;
}
private void OnEndRequest(object sender, EventArgs e)
{
TimeSpan ts = DateTime.Now - _StartTime;
HttpContext.Current.Response.Write("");
}
}
}
2.在web.config的中添加:



3.在要现实执行时间的页面中添加:

这里使用数据岛输出,其实所有的页面中都会有"",但是只有加了"
"的页面才会显示出来
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=896870