すべてのコントローラーが継承するコントローラーがあり、コントローラーのリクエストごとにコードを実行する必要があります。私は次のことを試しました:
protected override void Execute(System.Web.Routing.RequestContext requestContext)
{
if (Session["mallDetected"] == null)
{
Session["mallDetected"] = DateTime.Now.Ticks;
IList<Mall> malls = Mall.FindNearestByIp(Request.UserHostAddress);
if (malls.Count > 0)
{
Session["mall"] = malls[0];
}
}
base.Execute(requestContext);
}
しかし、どうやらセッション状態は、base.Execute()を呼び出した後まで、Executeメソッドで使用できません。これは私には機能しません。ASP.NET MVCのリクエストごとにこのセッションコードを実行できる場所はありますか?