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(ob ject sender, EventArgs e)
{
BeginRequestTim e = DateTime.Now;
}
private void application_End Request(object sender, EventArgs e)
{
HttpApplication application = (HttpApplicatio n)sender;
//Calculate elapsed time
PreSendContentT ime = DateTime.Now;
TimeSpan elapsedRequestT ime = PreSendContentT ime - BeginRequestTim e;
int elapsedMillisec onds =
Convert.ToInt32 (elapsedRequest Time.TotalMilli seconds);
application.Con text.Response.W rite("Elapsed Time: " +
elapsedMillisec onds.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