(結局、あきらめました)
他ではどうやって実現しているのだろう・・・
IIS 一台で実現ってのが無謀なのか?
ISAPI Extension の達人が身近にいるのか?
Content-Type: text/html;
なヘッダーを持つレスポンスに、強制的に広告等をねじ込むにはどうするか? ただし、IIS 一台で実現すること。別のマシン(プロキシ等)を利用せず。
× 純粋にドキュメントの末尾に追加する(</body>タグの後ろに追加する)ので、よろしくない。
× 拡張子 .htm の場合には対応してくれるが、.asp や .aspx .php .pl .cgi などその他諸々には無力。
× 私には難しすぎて実装できない。
× Filter より Extension を使うべきらしい。
TechNet Installing Wildcard Application Mappings (IIS 6.0) ワイルドカード アプリケーション マッピングをインストールする
MSDN Multiple Requests Mapped to an ISAPI Extension
× 私には難しすぎて実装できない。
MSDN Designing High-Performance ISAPI Applications
このあたりなら私でも実装できそうだが・・・
× </body>タグの直前に割り込ませる方法が見つからなかった。純粋にドキュメントの末尾に追加するなら可能。
× aspnet_isapi.dll を .htm や .html に割り当てる必要がある。よって .pl や .php .asp 等には無力。
残課題
△ 特定の場所を除き、残り全てに http module を強制的に導入する方法。そして、それを remove 出来ないようにする方法。多分、マシンレベルの web.config を上手に書けば実現できるだろう。あちこちから参照されるので http module は GAC に入れる必要有り。
Class1.cs
public class Class1 : IHttpModule
{
void IHttpModule.Dispose()
{
}
void IHttpModule.Init(HttpApplication context)
{
context.EndRequest += new EventHandler(context_EndRequest);
}
void context_EndRequest(object sender, EventArgs e)
{
HttpApplication app = sender as HttpApplication;
if (app != null)
{
app.Response.Output.Write("<a href=\"http://example.com/\">バイ○グラ</a>");
}
}
}
アプリレベルの web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
<authentication mode="Windows"/>
<httpModules>
<add name="Hoge" type="HttpModuleTest.Class1,
HttpModuleTest" lockItem="true"/>
</httpModules>
</system.web>
</configuration>
INFO ASP.NET HTTP Modules and HTTP Handlers Overview
[INFO] ASP.NET の HTTP モジュールと HTTP ハンドラの概要
HOW TO Use ASP.NET to Protect File Types
Full content protection using ASP.NET