当我的用户单击登录并通过身份验证时,我将他们重定向到此 ActionResult。它把他们带到了这个方法:
[Authorize]
private ActionResult RouteRegistrationStep()
{
Debug.Print(HttpContext.User.Identity.IsAuthenticated.ToString()); // false
Debug.Print(HttpContext.User.Identity.Name); // blank
return RedirectToAction("ContactInfo", "Adjuster");
}
怎么是HttpContext.User.Identity.IsAuthenticated.ToString()
假的?而且,如果它是假的,为什么[Authorize]
属性让它在方法开始?
编辑:
这是将它们重定向到的登录方法RouteRegistrationStep()
:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl)
{
if (ModelState.IsValid && db.Users.Where(x => x.username == model.username
&& x.password == EncryptPassword(model.password)).Count() > 0)
{
FormsAuthentication.SetAuthCookie(model.username, model.RememberMe);
return RedirectToLocal(returnUrl);
}
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
}
[Authorize]
private ActionResult RedirectToLocal(string returnUrl)
{
if (Url.IsLocalUrl(returnUrl))
{
return Redirect(returnUrl);
}
else
{
return RouteRegistrationStep();
}
}