Logoff dont work with MVC 5

Apr 3, 2014 at 7:44 AM
Just installed this, registering and login worked
  [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                WebSecurity.CreateUserAndAccount(model.UserName, model.Password);

                WebSecurity.Login(model.UserName, model.Password);
                return RedirectToAction("Index", "Home");
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var success = WebSecurity.Login(model.UserName, model.Password);
                if (success)
                {
                    return RedirectToLocal(returnUrl);
                }
                else
                {
                    ModelState.AddModelError("", "Invalid username or password.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
But my logout do not do anything
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult LogOff()
        {
            WebSecurity.Logout();
            return RedirectToAction("Index", "Home");
        }
I have checked that it is hit with a breakpoint, but nothing seems to happen
Coordinator
Apr 5, 2014 at 5:38 PM
Hello,

What you are expecting this method to do? After lgout, IPrincipal User will be empty in controller, and authorize attribute will not pass this user to action.

Regards,
Dima
Apr 15, 2014 at 8:38 PM
Edited Apr 15, 2014 at 8:38 PM
I expect it to un autherize me, if I click it I get forwarded to the front page and it says

"Hello skipper! Log off"

and on a controller where I have [Authorize] I can still access every action

So not sure why it dont log me out

Sorry for the late reply