Creating a Request timer HttpModule

Discussion in 'ASP .Net' started by =?Utf-8?B?TWFuc28=?=, Jun 21, 2006.

  1. Hi,

    We want to create a generic request timer that will inject the time it took
    to render each page as a HttpModule. We want to be able to inject this just
    before the finishing </body> tag but I can't seem to find a event to add an
    handler for. The timer should start in BeginRequest and end after the code in
    Render has been executed but then we don't have access to the controls
    collection anymore (and I can't hook up to the render event using the context
    in the HttpModule).

    How can this be accomplished? Any links or hints are welcomed!

    Thanks,
    Manso
     
    =?Utf-8?B?TWFuc28=?=, Jun 21, 2006
    #1
    1. Advertising

  2. Start your timer in the BeginRequest event as you stated. Then listen for the
    EndRequest event. The handler for the EndRequest stops your timer and injects
    the results into the Request just before it finishes.

    Ex.

    private void BeginRequest(object sender, EventArgs e)
    {
    BeginRequestTime = DateTime.Now;
    }


    private void application_EndRequest(object sender, EventArgs e)
    {
    HttpApplication application = (HttpApplication)sender;

    //Calculate elapsed time
    PreSendContentTime = DateTime.Now;
    TimeSpan elapsedRequestTime = PreSendContentTime - BeginRequestTime;

    int elapsedMilliseconds =
    Convert.ToInt32(elapsedRequestTime.TotalMilliseconds);

    application.Context.Response.Write("Elapsed Time: " +
    elapsedMilliseconds.ToString() );
    }
    --
    -Demetri


    "Manso" wrote:

    > Hi,
    >
    > We want to create a generic request timer that will inject the time it took
    > to render each page as a HttpModule. We want to be able to inject this just
    > before the finishing </body> tag but I can't seem to find a event to add an
    > handler for. The timer should start in BeginRequest and end after the code in
    > Render has been executed but then we don't have access to the controls
    > collection anymore (and I can't hook up to the render event using the context
    > in the HttpModule).
    >
    > How can this be accomplished? Any links or hints are welcomed!
    >
    > Thanks,
    > Manso
     
    =?Utf-8?B?RGVtZXRyaQ==?=, Jun 21, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kelsang Wangchuk

    System.Timers.Timer vs. System.Threading.Timer

    Kelsang Wangchuk, Jul 31, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    719
    Kelsang Wangchuk
    Jul 31, 2003
  2. =?Utf-8?B?U2hhcGlybw==?=

    HttpModule multithreading and request and response corelation

    =?Utf-8?B?U2hhcGlybw==?=, Dec 7, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    784
    Scott Allen
    Dec 8, 2004
  3. Replies:
    1
    Views:
    1,620
    Steve C. Orr [MVP, MCSD]
    Feb 22, 2005
  4. Simon

    page timer, or redirect timer

    Simon, Nov 4, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    11,218
    Bruce Barker
    Nov 4, 2005
  5. Replies:
    8
    Views:
    514
    Jorgen Grahn
    Jul 15, 2013
Loading...

Share This Page