Creating a Request timer HttpModule

G

Guest

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
 
G

Guest

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() );
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top