Here is my controller. Its not working for logged in users preventing access to the login page. Please help me out. I have used the request.Is Authenicated and User.Identity Methods in my controller
[HttpPost]
[AllowAnonymous]
public ActionResult Login(LoginViewModel model, string returnUrl)
{
if (Request.IsAuthenticated)
{
return RedirectToAction("Main","Home");
}
else if (!this.ModelState.IsValid)
{
return this.View(model);
}
else if (Membership.ValidateUser(model.Username, model.Password))
{
FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe);
if (this.Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
&& !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
{
return this.Redirect(returnUrl);
}
return this.RedirectToAction("Main", "Home");
}
this.ModelState.AddModelError(string.Empty,"Invalid Credentials.");
this.ModelState.AddModelError(string.Empty, "The user name or password provided is incorrect.");
return this.View(model);
}