来自Cuyahoga 使用自定义的PageHandler处理所有的aspx页面 获取页面的执行时间
 1using System;
 2using System.Web;
 3using System.Web.UI;
 4using System.Web.SessionState;
 5
 6namespace 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
 
 
webconfig中注册HttpHandler
<httpHandlers>
            
<add verb="*" path="*.aspx" type="Cuyahoga.Web.HttpHandlers.PageHandler, Cuyahoga.Web" />
</httpHandlers>
posted on 2007-10-01 06:56  mbskys  阅读(291)  评论(0)    收藏  举报