来自Cuyahoga 使用自定义的PageHandler处理所有的aspx页面 获取页面的执行时间
1
using System;
2
using System.Web;
3
using System.Web.UI;
4
using System.Web.SessionState;
5
6
namespace Cuyahoga.Web.HttpHandlers
7
{
8
/// <summary>
9
/// This class handles all aspx page requests for Cuyahoga.
10
/// </summary>
11
public class PageHandler : IHttpHandler, IRequiresSessionState
12
{
13
#region IHttpHandler Members
14
15
/// <summary>
16
/// Process the aspx request. This means (eventually) rewriting the url and registering the page
17
/// in the container.
18
/// </summary>
19
/// <param name="context"></param>
20
public void ProcessRequest(HttpContext context)
21
{
22
string rawUrl = context.Request.RawUrl;
23
DateTime startTime = DateTime.Now;
24
25
// Obtain the handler for the current page
26
string aspxPagePath = rawUrl.Substring(0, rawUrl.IndexOf(".aspx") + 5);
27
IHttpHandler handler = PageParser.GetCompiledPageInstance(aspxPagePath, null, context);
28
29
// Process the page just like any other aspx page
30
handler.ProcessRequest(context);
31
32
TimeSpan duration = DateTime.Now - startTime;
33
context.Response.Write(String.Format("Request finshed. Total duration: {0} ms.", duration.Milliseconds));
34
}
35
36
/// <summary>
37
///
38
/// </summary>
39
public bool IsReusable
40
{
41
get { return true; }
42
}
43
44
#endregion
45
}
46
}
47
using System;2
using System.Web;3
using System.Web.UI;4
using System.Web.SessionState;5

6
namespace Cuyahoga.Web.HttpHandlers7
{8
/// <summary>9
/// This class handles all aspx page requests for Cuyahoga.10
/// </summary>11
public class PageHandler : IHttpHandler, IRequiresSessionState12
{13
#region IHttpHandler Members14

15
/// <summary>16
/// Process the aspx request. This means (eventually) rewriting the url and registering the page 17
/// in the container.18
/// </summary>19
/// <param name="context"></param>20
public void ProcessRequest(HttpContext context)21
{22
string rawUrl = context.Request.RawUrl;23
DateTime startTime = DateTime.Now;24

25
// Obtain the handler for the current page26
string aspxPagePath = rawUrl.Substring(0, rawUrl.IndexOf(".aspx") + 5);27
IHttpHandler handler = PageParser.GetCompiledPageInstance(aspxPagePath, null, context);28

29
// Process the page just like any other aspx page30
handler.ProcessRequest(context);31

32
TimeSpan duration = DateTime.Now - startTime;33
context.Response.Write(String.Format("Request finshed. Total duration: {0} ms.", duration.Milliseconds));34
}35

36
/// <summary>37
/// 38
/// </summary>39
public bool IsReusable40
{41
get { return true; }42
}43

44
#endregion45
}46
}47

webconfig中注册HttpHandler
<httpHandlers>
<add verb="*" path="*.aspx" type="Cuyahoga.Web.HttpHandlers.PageHandler, Cuyahoga.Web" />
</httpHandlers>
<add verb="*" path="*.aspx" type="Cuyahoga.Web.HttpHandlers.PageHandler, Cuyahoga.Web" />
</httpHandlers>


浙公网安备 33010602011771号