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.TotalMillisecon ds);
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