重定向到每种角色类型的不同默认页面/控制器 - MVC 5

时间:2014-08-27 21:33:37

标签: asp.net asp.net-mvc-5 roles

您好我正在开发MVC5中的应用程序

登录后,登录用户自动重定向到HomeController的索引页面。

我有3种不同的罗勒: 1名运营商 2管理员 3 TicketManager

当操作员登录时,他应该被自动重定向到OperatorCOntroller的索引页面。

我试图找到一个解决方案很长一段时间但却无法找到一个可行的解决方案。 我试过HomeController的索引页面

if(User.isinrole("Operator")){return RedirectionOnAction("index","Operator")}

它有效,但不是理想的解决方案。

1 个答案:

答案 0 :(得分:0)

我能想到的最简单的事情:

string userRole = Roles.GetRolesForUser(User.Identity.Name).FirstOrDefault();
if (userRole != null) return RedirectToAction("Index", userRole);