1つの方法は、Session Expireの場合、すべてのアクションでそのセッションをチェックする必要があり、それがnullの場合は、ログインページにリダイレクトすることです。
しかし、これは非常に多忙なメソッドです。これを克服するには、これを実行
する独自のメソッドを作成する必要がありますActionFilterAttribute。すべてのアクションメソッドにこの属性を追加するだけです。
これは、ActionFilterAttributeをオーバーライドするクラスです。
public class SessionExpireFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
HttpContext ctx = HttpContext.Current;
// check if session is supported
CurrentCustomer objCurrentCustomer = new CurrentCustomer();
objCurrentCustomer = ((CurrentCustomer)SessionStore.GetSessionValue(SessionStore.Customer));
if (objCurrentCustomer == null)
{
// check if a new session id was generated
filterContext.Result = new RedirectResult("~/Users/Login");
return;
}
base.OnActionExecuting(filterContext);
}
}
次に、実際には次のようにこの属性を追加します。
[SessionExpire]
public ActionResult Index()
{
return Index();
}
これでうまくいきます。