我正在尝试将表单身份验证添加到 mvc 站点,当我运行应用程序时,我被重定向到登录页面(这是正确的)。但是,每次我尝试登录时,页面都会被刷新,并且控制器永远不会收到发布请求。我认为我的表单身份验证已关闭并将所有请求重定向回登录页面?任何帮助将不胜感激!
以下是我的网络配置信息:
<authentication mode="Forms">
<forms loginUrl="~/Account" timeout="30" slidingExpiration="false" requireSSL="false" />
</authentication>
<authorization>
<deny users ="?" />
<allow users = "*" />
</authorization>
下面是我的登录页面:
@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" />
}
下面是我的控制器:
[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);
}