3
votes

This is probably a silly question, but it seems as though RedirectToAction() isnt working correctly.

I have an Admin Controller done as a separate area, and I have a logout task method, and I am simply trying to get the method to redirect to the website index on logout, but it is taking me to a url under the admin route instead and I have no idea why as I am calling the method giving it the controller name and action method name inside that controller. instead it takes me to: http://localhost:63374/Admin/Home

Is there something I am doing wrong?

        [Route("logout")]
    public async Task<ActionResult> Logout()
    {
        var authManager = HttpContext.GetOwinContext().Authentication;

        authManager.SignOut();

        return RedirectToAction("index", "home");
    }
2

2 Answers

6
votes

When not specified, the route values are persisted between calls. Since you are in the admin area and not specifying an area in your RedirectToAction method, the route engine is keeping the reference to the admin area.

To solve this, you can either:

  • Move your logout action outside of the admin area or,
  • Specify that the RedirectToAction should find a controller outside of the current area by setting the area to an empty string.

return RedirectToAction("Index", new{controller="Home", area=string.Empty});

1
votes

Try to use return RedirectToAction("Index", "Home");. As i know, all these Redirect* and RedirectTo* methods are case sensitive