程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> ASP.NET >> 關於ASP.NET >> 使用自定義的PageHandler處理aspx頁面獲取頁面的執行時間

使用自定義的PageHandler處理aspx頁面獲取頁面的執行時間

編輯:關於ASP.NET

使用自定義的PageHandler處理所有的aspx頁面獲取頁面的執行時間

using System;
using System.Web;
using System.Web.UI;
using System.Web.SessionState;

namespace Cuyahoga.Web.HttpHandlers
{
  /// <summary>
  /// This class handles all aspx page requests for Cuyahoga.
  /// </summary>
  public class PageHandler : IHttpHandler, IRequiresSessionState
  {
    #region IHttpHandler Members
    /// <summary>
    /// Process the aspx request. This means (eventually) rewriting the url and registering the page
    /// in the container.
    /// </summary>
    /// <param name="context"></param>
    public void ProcessRequest(HttpContext context)
    {
      string rawUrl = context.Request.RawUrl;
      DateTime startTime = DateTime.Now;
      // Obtain the handler for the current page
      string aspxPagePath = rawUrl.Substring(0, rawUrl.IndexOf(".aspx") + 5);
      IHttpHandler handler = PageParser.GetCompiledPageInstance(aspxPagePath, null, context);

      // Process the page just like any other aspx page
      handler.ProcessRequest(context);
      TimeSpan duration = DateTime.Now - startTime;
      context.Response.Write(String.Format("Request finshed. Total duration: {0} ms.",
        duration.Milliseconds));
    }

    /// <summary>
    ///
    /// </summary>
    public bool IsReusable
    {
      get { return true; }
    }
    #endregion
  }
}

webconfig中注冊HttpHandler

<httpHandlers>
  <add verb="*" path="*.aspx"
     type="Cuyahoga.Web.HttpHandlers.PageHandler,Cuyahoga.Web" />
</httpHandlers>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved