I have my auth controller which on successful login redirects the user to my dashboard controller with the user.identity properties populated, so I can use User.IsAuthenticated
and User.IsInRole("Admin")
My question is.
Once the user is logged in and are on the dashboard page. How can I redirect them back to the dashboard page if they're already logged in.
Thanks in advance.
So my solution was to simply check if the user was already authenticated in my [HttpGet]
login controller as opposed to my [HttpPost]
login controller.
[HttpGet]
public ActionResult Login()
{
if (User.Identity.IsAuthenticated)
return RedirectToAction("Index", "Dashboard");
return View();
}
[HttpPost]
public async Task<IActionResult> Login(LoginViewModel req)
{
return View(req);
}