我是 IIS 模块和 C# 领域的新手。
在网站将页面内容发送给客户端之前,我需要修改网站特定目录中的静态 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 检索页面内容的正确方法吗?
谢谢并恭祝安康。