1

ASP.NET MVC 4 で独自のログイン/ログアウト モジュールに取り組んでおり、ログアウト アクションの結果でセッションをクリアし、次のコードを使用してキャッシュを保存していません。

[HttpGet]
        public ActionResult Login()
        {
            return View();
        }

        [OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")]
        [HttpPost]
        public ActionResult Login(Models.User user)
        {
            if (ModelState.IsValid)
            {
                if (user.IsValid(user.UserName, user.Password))
                {
                    FormsAuthentication.SetAuthCookie(user.UserName, user.RememberMe);
                    return RedirectToAction("Index", "Admin");
                }
                else
                {
                    ModelState.AddModelError("", "Login data is incorrect!");
                }
            }
            return View(user);
        }
        public ActionResult Logout()
        {

            FormsAuthentication.SignOut();
            Session.Clear();
            Session.Abandon();
            Session.RemoveAll();
            return RedirectToAction("Index", "Home");
        }

ホームインデックスコントローラー

 [Authorize]
        public ActionResult Index()
        {
            return View();
        }

レイアウト cshtml

 @if (Request.IsAuthenticated)
                {
                    <strong>@Html.Encode(User.Identity.Name)</strong>
                    @Html.ActionLink("Sign Out", "Logout", "User")
                    @Html.ActionLink("Grid", "Index", "Admin")
                }
                else
                {
                    @Html.ActionLink("Sign In", "Login", "User")
                }

フォーム認証を使用しており、すべて正常に動作しますが、ページからログアウトした後も、戻るボタンをクリックして保護されたページにアクセスできます。

どこを間違えているか分かるかな

4

1 に答える 1

1

ばかげた間違い、[OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")]ログインの代わりに安全なページで使用する必要があります。

于 2013-11-13T15:27:16.073 に答える