0

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?

trashr0x
  • 6,457
  • 2
  • 29
  • 39
Heidel
  • 3,174
  • 16
  • 52
  • 84

1 Answers1

2
public class HomeController : Controller
{
    public ActionResult Index()
    {
        if (Request.IsAuthenticated)                
        {
            return RedirectToAction("Index", "Task");
        }
        return View();
    }
}
trashr0x
  • 6,457
  • 2
  • 29
  • 39