私は実際に私が利用しているものを次の投稿に従っています。
https://stackoverflow.com/a/15939899/1118485
ご覧のとおり、これは のメソッドの 1 つにのみ実装されていますHomeController
。コードの書き直しを避けるために、BaseController
.
protected new ViewResult View()
{
if (Session["sessionid"] == null )
{
//Session["sessionid"] = "empty";
return base.View();
}
// check to see if your ID in the Logins table has LoggedIn = true - if so, continue, otherwise, redirect to Login page.
if (OperationContext.IsYourLoginStillTrue(System.Web.HttpContext.Current.User.Identity.Name, Session["sessionid"].ToString()))
{
// check to see if your user ID is being used elsewhere under a different session ID
if (!OperationContext.IsUserLoggedOnElsewhere(System.Web.HttpContext.Current.User.Identity.Name, Session["sessionid"].ToString()))
{
//return base.View();
}
else
{
// if it is being used elsewhere, update all their Logins records to LoggedIn = false, except for your session ID
OperationContext.LogEveryoneElseOut(System.Web.HttpContext.Current.User.Identity.Name, Session["sessionid"].ToString());
//return base.View();
}
}
else
{
FormsAuthentication.SignOut();
Attention("You have logged out because another user with the account has been connnected.");
//return RedirectToAction("Login", "Account");
}
return base.View();
}
しかし、ご覧のとおり、これはView
メソッドを使用する場合にのみ機能します。他のコントローラーでは、いくつかのまたはを使用しましRedirects
たFileResult
。したがって、すべての ActionResult が実行される必要があります。上記のコードを確認してください。ActionResultAttribute
調査中に、すべてのコントローラーにカスタムを実装する必要があると思いましたが、そうですか?
私が正しければ、カスタムを使用してActionResultAttr
常にログインを確認する方法についてのデモ実装を見せてもらえますか。または、私が間違っている場合、どうすればよいですか?