すべてのリクエストの最後にいくつかのアクションを実行しようとしています。テストを行うために新しいプロジェクトを作成したときに生成される Application_Start() を変更しました。
protected void Application_Start()
{
EndRequest += (s, e) =>
{
Console.Write("fghfgh");
};
RegisterRoutes(RouteTable.Routes);
}
ラムダは呼び出されません。理由はありますか?
編集: SharpArch [ http://code.google.com/p/sharp-architecture/]で同様のことを行っていることがわかりますが、そこでは機能します...いいえ、HttpModule を使用したくありません.
edit2: 私が見つけた唯一の回避策は、Application_EndRequest を global.asax のプライベート静的メンバーと組み合わせて使用することです。
private static WebSessionStorage wss;
protected void Application_Start()
{
//...
wss = new WebSessionStorage(this);
//...
}
protected void Application_EndRequest(object sender, EventArgs e)
{
wss.EndRequest(sender, e);
}
Application_EndRequest が別のインスタンス オブジェクト (this) を使用して呼び出されているように見えるため、wss はプライベートである必要があります。これは、(最初に説明したように) 私のイベントが呼び出されない理由でもあります。