这是我的代码,我不知道为什么它总是执行 else 语句,即使我登录具有 SuperAdmin 角色的用户 [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return View(model); } // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false); if (User.IsInRole("SuperAdmin")) { switch (result) { case SignInStatus.Success: return RedirectToLocal(returnUrl); case SignInStatus.LockedOut: return View("Lockout"); case SignInStatus.RequiresVerification: return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt."); return View(model); } } else { ModelState.AddModelError("", "you are not allowed to access this page"); //AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie); return View(model); } }给我一些建议我应该怎么做我的代码来改进它..我的问题是为什么我的代码总是执行 else 语句,即使我使用 SuperAdmin 的帐户
1 回答
- 1 回答
- 0 关注
- 120 浏览
添加回答
举报
0/150
提交
取消