2

私は IIS モジュールと C# の分野に不慣れです。

Web サイトがページ コンテンツをクライアントに送信する前に、Web サイトの特定のディレクトリにある静的 HTML ファイルのコンテンツを変更する必要があります。変更には、バナー、フッターなどの追加が含まれます。

私の調査によると、IIS モジュールを使用して目標を達成できるはずです (正しいですか?)。これが私のコードです:

namespace MyProject
{
    public class MyModule : IHttpModule
    {
        #region IHttpModule Members

        public void Dispose()
        {

        }

        public void Init(HttpApplication context)
        {
            context.PreSendRequestContent +=
                new EventHandler(onPreSendRequestContent);
        }

        #endregion

        public void onPreSendRequestContent(Object source, EventArgs e)
        {
            HttpApplication app = (HttpApplication)source;
            HttpRequest request = app.Context.Request;
            HttpResponse response = app.Context.Response;

            if (request.Path.Contains("my_specific_directory"))
            {
                //add banner and footer to the page content
                //which class, methods, or properties to use?
            }
        }
    }
}

PreSendRequestContent がページ コンテンツの変更を開始する適切なイベントであるかどうかはわかりません。ページ コンテンツを IIS で取得する正しい方法を教えてもらえますか?

ありがとうございます。

4

1 に答える 1