2

I'm trying to set up an application that will route to different areas of my application based on their groups in Active Directory using Windows Authentication.

For example, I have a user that is in an Admin group gets routed to one area, and a User group that gets routed to another.
All users will enter the app using the same url, but based on the group they are in it will forward them to their proper areas.

I'm not sure where this is handled? If anyone has a link of a scenario where this question is already answered that would be great.

Any help and guidance is appreciated and let me know if you need more information or if I am unclear in this description.

1

2 Answers 2

3

Role/group based routing is not supported by ASP.NET MVC, you can redirect to appropriate action in your Home Controller Index like following.

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

You are searching this, likely:

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);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.