-1

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);
}
4

1 に答える 1

1

System.Threading.Thread.CurrentPrincipalも 参照してください。

  • AuthenticationType "フォーム"
  • IsAuthenticated true
  • 名前「フレッド」

MVC/IIS にコントローラーを承認するように指示しましたか? 例えば

[Authorize]
public class MyController : Controller

User.Identityが設定されていない場合 は、WEB.CONFIG または明示的な AUTHORIZE 属性が欠落していることを示唆しています。

于 2013-01-31T03:01:44.867 に答える