1

I created a custom module based on two articles:

http://community.devexpress.com/blogs/paulk/archive/2009/03/30/implementing-an-ihttpmodule.aspx

And the module based on:

How do I display the duration it took to generate a page in a pages footer?

I have added the following class:

public class PerformanceMonitorModule : IHttpModule
{
    public void Init(HttpApplication context)
    {
        context.PreRequestHandlerExecute += delegate(object sender, EventArgs e)
        {
            //Set Page Timer Star
            HttpContext requestContext = ((HttpApplication)sender).Context;
            Stopwatch timer = new Stopwatch();
            requestContext.Items["Timer"] = timer;
            timer.Start();
        };
        context.PostRequestHandlerExecute += delegate(object sender, EventArgs e)
        {

            HttpContext httpContext = ((HttpApplication)sender).Context;
            HttpResponse response = httpContext.Response;
            Stopwatch timer = (Stopwatch)httpContext.Items["Timer"];
            timer.Stop();

            // Don't interfere with non-HTML responses
            if (response.ContentType == "text/html")
            {
                double seconds = (double)timer.ElapsedTicks / Stopwatch.Frequency;
                string result_time = string.Format("{0:F4} sec ", seconds);
                RenderQueriesToResponse(response, result_time);
            }
        };
    }
    void RenderQueriesToResponse(HttpResponse response, string result_time)
    {
        response.Write("<div style=\"margin: 5px; background-color: #FFFF00\"");
        response.Write(string.Format("<b>Page Generated in " + result_time));
        response.Write("</div>");
    }
    public void Dispose() { /* Not needed */ }
} // End of PerformanceMonitorModule

And the following to my web.config:

<system.web>
  ...
  <httpModules>
    <add name="PerformanceMonitorModule" type="PerformanceMonitorModule"/>
  </httpModules>
</system.web>

I have set breakpoints in the PerformanceMonitorModule classes init method and it never gets called.

A few notes:

  • The website is running on HTTPS. I don't think this would make a difference though?
  • The website is running in the Azure computer emulator. Not sure if this would cause any issues.
  • I have tried putting the assembly qualified name (MySite.Website.Business.Modules.PerformanceMonitorModule, MySite.Website, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null).

I'm not sure what else to try in order to get this module to load?

1
  • Have you looked at this?
    – Mark M
    Commented Jun 28, 2012 at 14:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.