我遇到了 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);
}