Reputation: 16420
Have looked at all the posts on here and none of them are fixing my issue.
I Hit the URL: /Users/KickOutUser
public void KickOutUser()
{
TempData["ErrorMessage"] = "You need to be logged in to access that content";
//Redirect to Login
RedirectToAction("Login");
}
/*user controller*/
public ActionResult Login()
{
//E.G ErrorMessage comes from HandleUnauthenticatedUser
ViewData["ErrorMessage"] = TempData["ErrorMessage"] ?? null;
return View();
}
With debugging, I can see it hit the first method, then redirect, but the redirect call never calls the Login method, and I end up with a blank view..
Upvotes: 0
Views: 206
Reputation: 47784
public void KickOutUser()
This method is not returning anything, read this
So in this case, what you can do is return ActionResult
or better ViewResult
like as shown below,
public ActionResult KickOutUser()
{
TempData["ErrorMessage"] = "You need to be logged in to access that content";
//Redirect to Login
return RedirectToAction("Login");
}
Hope this helps :)
Upvotes: 2
Reputation: 93434
You have to return RedirectToAction from an action method (that has an ActionResult return type). Calling RedirectToAction by itself will not do anything.
This is not how you should be handling security, though. You should instead be using an AuthorizationFilter to control access.
Upvotes: 1