1

ユーザーがログインをクリックして認証されると、ユーザーをこの 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()偽ですか?また、それが false である場合、[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();
    }
}
4

1 に答える 1