Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Creating a Request timer HttpModule

Reply
Thread Tools

Creating a Request timer HttpModule

 
 
=?Utf-8?B?TWFuc28=?=
Guest
Posts: n/a
 
      06-21-2006
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
 
Reply With Quote
 
 
 
 
=?Utf-8?B?RGVtZXRyaQ==?=
Guest
Posts: n/a
 
      06-21-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I know about the shutdown timer, is there a "switch on" timer... Mal Carter Computer Support 3 01-12-2008 01:58 AM
page timer, or redirect timer Simon ASP .Net 1 11-04-2005 07:14 PM
System.Timers.Timer/System.Threading.Timer Not Firing At All on Dev Server james.e.coleman@gmail.com ASP .Net 1 02-22-2005 09:41 PM
HttpModule multithreading and request and response corelation =?Utf-8?B?U2hhcGlybw==?= ASP .Net 7 12-08-2004 01:41 PM
System.Timers.Timer vs. System.Threading.Timer Kelsang Wangchuk ASP .Net 0 07-31-2003 04:28 PM



Advertisments