I have created HomeController
decorated with AuthorizeAttribute
, and also created AccountController
, but it is not redirecting to the Login()
action of AccountController
.
Home controller:
[Authorize]
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
}
Account controller:
public class AccountController : Controller
{
[HttpGet]
public ActionResult Login()
{
return View();
}
[HttpPost]
public ActionResult Login(LogOnCustom log)
{
if(ModelState.IsValid)
{
if(Membership.ValidateUser(log.UserName,log.Password))
{
FormsAuthentication.RedirectFromLoginPage(log.UserName, log.Isremeber);
}
else
{
ModelState.AddModelError("", "logOn error");
}
}
return View(log);
}
}
web.config:
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" >
</forms>
</authentication>