我在这里有这些代码的登录POST和GET不能重定向角色的看法
[Authorize]
public class AccountController : Controller
{
//
// GET: /Account/Login
[AllowAnonymous]
public ActionResult Login(string returnUrl)
{
ViewBag.ReturnUrl = returnUrl;
return View();
}
//
// POST: /Account/Login
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl)
{
if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
{
return RedirectToLocal(returnUrl);
}
if (User.IsInRole("Owner"))
{
return RedirectToAction("Index", "AdminOnly");
}
// If we got this far, something failed, redisplay form
ModelState.AddModelError("", "The user name or password provided is incorrect.");
return View(model);
}
我的问题,但是,当我尝试登录管理员帐户,我得到重定向到〜/共享/布局。我该怎么办?提前致谢!
如果你的第一个'if'语句有效,你会重定向你。你永远不会到达第二个“if”(假设用户是“所有者”,你的期望是如何) – 2015-02-07 05:40:31