There is user log in on home page in modal window using ajax (it uses method LogIn
from User
Controller)
[HttpPost]
[AjaxAction]
public ActionResult LogIn(UserModel user)
{
if (ModelState.IsValid)
{
if (IsValid(user.Email, user.Password))
{
FormsAuthentication.SetAuthCookie(user.Email, false);
return Json(new { status = "OK", message = "Success" }, JsonRequestBehavior.AllowGet);
}
}
return Json(new { status = "ERROR", message = "Data is incorrect" }, JsonRequestBehavior.AllowGet);
}
and if log in was successful, I do redirect on Task/Index
page.
I would like to add check in Index
action of Home
Controller, if user already is authorized, redirect him to Task/Index
, otherwise to show Index
view of Home
Controller.
I tried code below
public class HomeController : Controller
{
public ActionResult Index()
{
if (User.Identity.IsAuthenticated)
{
return Redirect("/Task/Index");
}
return View();
}
}
but redirect works in any case. How to fix it?