0

MembershipFormsAuthenticationを使用したログインにビルトインを使用しています。管理者が他のユーザーアカウントを無効にできるようにしたいのですがIsApproved、ユーザーのプロパティをfalseに変更することを考えましたが、機能せず、ログインしているユーザーが表示されました。これは、永続的なCookieが原因で発生したと思います。以前SetAuthCookieにユーザー用に設定しました。

私は調べましたが、ユーザーがまだ存在している/アクティブであることを確認するためFormsAuthenticationTicketSetAuthCookie、リポジトリに対して時々それらを再検証する方法を見つけることができないようです。

これは既存の機能でカバーされていますか?

ありがとう

4

1 に答える 1

1

認証パイプラインがどのように機能するかによって大きく異なります。一般的な考え方は次のとおりです。すべてのリクエストで、DB からユーザーのデータを取得します。

public User CurrentUser
        {
            get
            {
                if (_CurrentUser == null && Request.IsAuthenticated)
                {
                    //your method to get the user
                    _CurrentUser = _UserRepository.GetUserByEmail(HttpContext.User.Identity.Name); 
                }
                return _CurrentUser;
            }
        }

次に、ActionFilter を使用して確認できます。

 protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //user enabled?
            if (CurrentUser != null && !CurrentUser.IsApproved)
            {
                //Force LogOut
                //Redirect to LogOut
                filterContext.Result = new RedirectToRouteResult(
                new RouteValueDictionary {{ "Controller", "Account" },
                                      { "Action", "LogOff" } });
            }
}
于 2013-02-15T03:03:16.230 に答える