MVC4 ユーザー認証に問題があります。
System.Web.Security.Membership.ValidateUser
戻り値true.
その後FormsAuthentication.SetAuthCookie
、ブラウザに Cookie が表示されます。
その後、何らかの理由でUser.Identity.IsAuthenticated
まだ評価されます。false
User.Identity.IsAuthenticated
false
リダイレクト後も残りますfalse.
model.UserName
null or empty
私が電話した場合はありませんSetAuthCookie
。正しいユーザー名があります。
フォーム認証はweb.config.
[AllowAnonymous]
[HttpPost]
public ActionResult Login(LoginModel model, string returnUrl)
{
if (ModelState.IsValid)
{
if (System.Web.Security.Membership.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
if (Url.IsLocalUrl(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RedirectToAction("Index", "Home");
}
}
else
{
ModelState.AddModelError("", "The user name or password provided is incorrect.");
}
}
// If we got this far, something failed, redisplay form
return View(model);
}