ASP.NET Windows 身份验证路由不同组

ASP.NET Windows Authentication routing different groups

我正在尝试设置一个应用程序,该应用程序将使用 Windows 身份验证根据 Active Directory 中的组路由到我的应用程序的不同区域。

例如,我有一个管理员组中的用户被路由到一个区域,而一个用户组被路由到另一个区域。
所有用户都将使用相同的 url 进入该应用程序,但会根据他们所在的组将他们转发到适当的区域。

我不确定这是在哪里处理的?如果有人 link 已经回答了这个问题,那就太好了。

感谢您提供任何帮助和指导,如果您需要更多信息或者如果我在此描述中不清楚,请告诉我。

Role/group ASP.NET MVC 不支持基于路由,您可以重定向到您的 Home Controller Index 中的适当操作,如下所示。

if (User.IsInRole("Admin"))
{
    return RedirectToAction("Index", "AdminController");
}

您正在搜索这个,可能是:

1.

public ActionResult LogIn(string userName, string password)
{

  if (!Membership.ValidateUser(userName, password))
  {
    Redirect("http://goaway.com");
  }

  string[] userRoles = Roles.GetRolesForUser();
  string
    controller,
    action;

  if (userRoles.Contains("Role1"))
  {
    controller = "Role1";
    action = "Index";
  }
  else if (userRoles.Contains("Role2"))
  {
    controller = "Role2";
    action = "Index2";
  }
  else
  {
    throw new InvalidOperationException("Bad user!");
  }

  return RedirectToActionPermanent(action, controller);
}
<configuration>
  <system.web>
    <roleManager enabled="true" />
  </system.web>
</configuration>

2.

public ActionResult LogIn2(string userName, string password)
{

  if (!Membership.ValidateUser(userName, password))
  {
    Redirect("http://goaway.com");
  }

  string
    controller,
    action;

  if (User.IsInRole("Admins"))
  {
    controller = "Admins";
    action = "LogIn";
  }
  else if (User.IsInRole("Editors"))
  {
    controller = "Editors";
    action = "LogIn";
  }
  else
  {
    controller = "LogOut";
    action = "LogoOut";
  }

  return RedirectToActionPermanent(action, controller);
}