我想向mvc网站添加窗体身份验证,当我运行应用程序时,我被重定向到登录页面(这是正确的)。但是,每次尝试登录时,页面都会刷新,而控制器永远不会收到请求。我认为我的表单身份验证的某些内容已关闭,并将所有请求重定向回登录页面?任何帮助将不胜感激!下面mvc窗体身份验证重定向
是我的web配置信息:
<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);
}
谢谢,这工作! – spyter
@ user587950,很高兴我可以提供帮助,请将其标记为我自己和社区的答案! –