我想向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,很高興我可以提供幫助,請將其標記爲我自己和社區的答案! –