I am trying to add forms authentication to an mvc site and when i run the application I am redirected to the login page (which is correct). However, everytime I try to log in, the page is just refreshed instead and the controller is never getting the post request. I think something with my forms authentication is off and its redirecting all requests back to the login page? Any help would be greatly appreciated!
below is my web config info:
<authentication mode="Forms">
<forms loginUrl="~/Account" timeout="30" slidingExpiration="false" requireSSL="false" />
</authentication>
<authorization>
<deny users ="?" />
<allow users = "*" />
</authorization>
Below is my login page:
@using (Html.BeginForm("Login", "Account", FormMethod.Post))
{
@Html.LabelFor(x => x.Username)<br />
@Html.TextBoxFor(x => x.Username)
<br />
<br />
@Html.LabelFor(x => x.Password)<br />
@Html.TextBoxFor(x => x.Password)
<br />
<br />
<br />
<input type="submit" value="Login" />
}
Below is my controller:
[HttpGet]
public ActionResult Index()
{
return View("~/Views/Account/Login.cshtml", new LoginViewModel());
}
[HttpPost]
public ActionResult Login(LoginViewModel viewModel)
{
Membership.ValidateUser(viewModel.Username, viewModel.Password);
FormsAuthentication.SetAuthCookie(viewModel.Username, viewModel.RememberMe);
return View("~/Views/Account/Login.cshtml", viewModel);
}