利用IHttpHandler计算页面的执行时间
2007-11-01 22:00
489 查看
使用自定义的PageHandler处理所有的aspx页面 获取页面的执行时间
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.SessionState;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
namespace Cuyahoga.Web.HttpHandlers
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//**//**//// <summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// This class handles all aspx page requests for Cuyahoga.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
/// </summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public class PageHandler : IHttpHandler, IRequiresSessionState
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
IHttpHandler MembersIHttpHandler Members#region IHttpHandler Members
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//**//**//// <summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// Process the aspx request. This means (eventually) rewriting the url and registering the page
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// in the container.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// </summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
/// <param name="context"></param>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public void ProcessRequest(HttpContext context)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string rawUrl = context.Request.RawUrl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DateTime startTime = DateTime.Now;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// Obtain the handler for the current page
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string aspxPagePath = rawUrl.Substring(0, rawUrl.IndexOf(".aspx") + 5);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
b487
IHttpHandler handler = PageParser.GetCompiledPageInstance(aspxPagePath, null, context);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// Process the page just like any other aspx page
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
handler.ProcessRequest(context);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TimeSpan duration = DateTime.Now - startTime;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
context.Response.Write(String.Format("Request finshed. Total duration: {0} ms.", duration.Milliseconds));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//**//**//// <summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
///
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
/// </summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public bool IsReusable
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
get ...{ return true; }
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
#endregion
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
webconfig中注册HttpHandler
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<httpHandlers>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<add verb="*" path="*.aspx" type="Cuyahoga.Web.HttpHandlers.PageHandler, Cuyahoga.Web" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</httpHandlers>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.UI;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using System.Web.SessionState;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
namespace Cuyahoga.Web.HttpHandlers
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//**//**//// <summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// This class handles all aspx page requests for Cuyahoga.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
/// </summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public class PageHandler : IHttpHandler, IRequiresSessionState
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
IHttpHandler MembersIHttpHandler Members#region IHttpHandler Members
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//**//**//// <summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// Process the aspx request. This means (eventually) rewriting the url and registering the page
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// in the container.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
/// </summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
/// <param name="context"></param>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public void ProcessRequest(HttpContext context)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string rawUrl = context.Request.RawUrl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DateTime startTime = DateTime.Now;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// Obtain the handler for the current page
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string aspxPagePath = rawUrl.Substring(0, rawUrl.IndexOf(".aspx") + 5);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
b487
IHttpHandler handler = PageParser.GetCompiledPageInstance(aspxPagePath, null, context);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// Process the page just like any other aspx page
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
handler.ProcessRequest(context);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
TimeSpan duration = DateTime.Now - startTime;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
context.Response.Write(String.Format("Request finshed. Total duration: {0} ms.", duration.Milliseconds));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
/**//**//**//// <summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
///
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
/// </summary>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public bool IsReusable
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
get ...{ return true; }
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
#endregion
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
webconfig中注册HttpHandler
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<httpHandlers>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<add verb="*" path="*.aspx" type="Cuyahoga.Web.HttpHandlers.PageHandler, Cuyahoga.Web" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</httpHandlers>
相关文章推荐
- 利用IHttpHandler计算页面的执行时间
- 利用IHttpHandler计算页面的执行时间
- 利用IHttpHandler计算页面的执行时间
- 利用IHttpHandler计算页面的执行时间
- 利用IHttpHandler计算页面的执行时间
- 利用IHttpHandler计算页面的执行时间
- 利用IHttpHandler计算页面的执行时间
- 计算php页面执行时间类
- PHP计算页面执行时间
- Asp计算页面执行的时间
- js 页面执行时间计算代码
- 一:理解ASP.NET的运行机制(例:通过HttpModule来计算页面执行时间)
- asp.net计算每个页面执行时间的方法
- asp.net 通过httpModule计算页面的执行时间
- PHP 计算页面执行时间
- 解析PHP计算页面执行时间的实现代码
- asp.net计算页面执行时间
- 计算页面执行时间
- 一:理解ASP.NET的运行机制(例:通过HttpModule来计算页面执行时间)
- php计算一个页面执行时间函数写法