我有一个控制器CMS
,你可以在这里看到:
[HttpGet]
public ActionResult Login(string returnUrl)
{
return View(); // show the login page
}
UserRepository ObjUserRepository = new UserRepository();
[HttpPost]
public ActionResult Login(DomainClass.User loginInfo, string returnUrl)
{
if (ObjUserRepository.FindBy(i => i.Email == loginInfo.Email & i.Password == loginInfo.Password).Any())
{
DomainClass.User objUser = ObjUserRepository.FindBy(i => i.Email == loginInfo.Email & i.Password == loginInfo.Password).FirstOrDefault();
FormsAuthentication.SetAuthCookie(loginInfo.Email, false);
if (shouldRedirect(returnUrl))
{
return Redirect(returnUrl);
}
if (objUser.Pemission == "professor")
{
return RedirectToAction("Index", "Home", new { Area = "Teacher" });
}
}
return View(loginInfo);
}
我调用此网址../cms/login
并显示我的login
视图,我输入username
和password
,执行此部分代码:
if (objUser.Pemission == "professor")
{
return RedirectToAction("Index", "Home", new { Area = "Teacher" });
}
但是mvc再次将我重定向到了Login页面,但它应该将我重定向到/teacher/home/index
答案 0 :(得分:1)
更改
return RedirectToAction("Index", "Home", new { Area = "Teacher" });
要
return RedirectToAction("Index", "Home", new { area = "Teacher" });
area
参数是小写。