1

2 つの記事に基づいてカスタム モジュールを作成しました。

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

モジュールは次のものに基づいています。

ページのフッターにページの生成にかかった時間を表示するにはどうすればよいですか?

次のクラスを追加しました。

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

そして、私のweb.configへの以下:

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

PerformanceMonitorModuleクラスの init メソッドにブレークポイントを設定しましたが、呼び出されません。

いくつかのメモ:

  • Web サイトは HTTPS で実行されています。これでも変わらないと思いますが?
  • Web サイトは Azure コンピューター エミュレーターで実行されています。これが問題を引き起こすかどうかはわかりません。
  • アセンブリ修飾名 (MySite.Website.Business.Modules.PerformanceMonitorModule、MySite.Website、Version=1.0.0.0、Culture=neutral、PublicKeyToken=null) を入れてみました。

このモジュールをロードするために他に何を試せばよいかわかりません。

4

0 に答える 0