简体   繁体   中英

MVC5 LogOff and ReturnToAction not working

I have the following method that I know is being hit as I attached the debugger to it.

 [HttpPost]
 [AllowAnonymous]
 [ValidateAntiForgeryToken]
 Public ActionResult LogOff()
 {
     AuthenticationManager.SignOut();
     return RedirectToAction("Login", "Account", null);
 }

the Sign Out is working, but the Redirect To Action does nothing. the user is definitely logged off as if I click on any button on my site, it takes me back to the log in page. So its as though the return RedirectToAction() is not executing. Looking at the Response in the Browser, all that is being sent back is /Account/Login.

So what do I need to change to get this to work, or should I not be using ReturnToAction at all?

You can use Redirect method:

return Redirect("~/Account/Login");

OR

Define this route in RouteConfig.cs

routes.MapRoute(
 "MyRoute", // Route name
 "Account/", // URL 
 new { controller = "Account", action = "Login"} // Parameter defaults
 );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM