【发布时间】:2015-04-07 08:54:55
【问题描述】:
我这里有用于登录 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);
}
然而,我的问题是,当我尝试登录管理员帐户时,我会重定向到 ~/Shared/Layout.我该怎么办?提前致谢!
【问题讨论】:
-
您的第一个
if语句如果有效则重定向您。你永远不会到达第二个if(如果用户是“所有者”,我认为这是你期望做的)
标签: c# asp.net-mvc roles