locked
how to get the httpmodule to print the result all times? RRS feed

  • Question

  • User-334574633 posted

    Hello, i have been playing around with httpmodules but i cant get them to work the way i want. i want to print a message on Every page and display how long it took to render this page, this is the code that i wrote, but it only prints it the first time i get to the site, when i click a link or refresh the page i get nothing?

    public class TimeConsumption : IHttpModule
    {

    private HttpContext _current = null;
    private long _beginRequest;

    public void Dispose()
    {
    throw new Exception("The method or operation is not implemented.");
    }

    public void Init(HttpApplication context)
    {
    _current = context.Context;
    context.BeginRequest += new EventHandler(context_BeginRequest);
    context.EndRequest += new EventHandler(context_EndRequest);
    }

    void context_BeginRequest(object sender, EventArgs e)
    {
    _beginRequest =
    DateTime.Now.Ticks;
    }

    void context_EndRequest(object sender, EventArgs e)
    {
    DateTime _ProcessTime = DateTime.Now.AddTicks(-_beginRequest);
    _current.Response.Output.Write(
    "<!-- Processing time: " + _ProcessTime.Second.ToString() + ":" + _ProcessTime.Millisecond.ToString() + " second(s) -->");
    }

    }

    This generates in that the time prints one time the first time i load the page, when i click a link or refresh nothing happens, i have also tried to change EndRequest into PreSendRequestContent but when i do that i get nothing back on any page. Have i missed something?

    Friday, December 1, 2006 12:05 PM

All replies