locked
current group in active directory RRS feed

  • Question

  • User-532807843 posted

    Hello,

    I am trying to return the Active Directory Group name of the current logged in user. i have the following code below.. what am i doing wrong? the code i have is bringing ALL active directory group names.

     

    protected string GetGroup()

    {

    string grps = string.Empty;

    WindowsIdentity user = (WindowsIdentity)User.Identity;

    IdentityReferenceCollection ntgroups = user.Groups.Translate(typeof(NTAccount));foreach (IdentityReference group in ntgroups)

    {

    if (group is NTAccount)

    {

    grps += group.ToString() +
    "<br />";

    }

    }

    return grps;

    LabelIdentityGroup.Text = grps;

    }

     

    Thanks

     

     

    Friday, February 20, 2009 12:21 PM

All replies

  • User1191518856 posted

    What group are you trying to return? The primary group (domain users)? As long as your user is member of more than one group, your code will (correctly) enumerate all of them.

    Saturday, February 21, 2009 5:52 PM
  • User-532807843 posted

    Thanks for the reply. i am trying to check their current group. The group that gives them access to the page. Does that make sense?

    Monday, February 23, 2009 12:38 PM
  • User1191518856 posted

    I'm afraid not. There may be several groups that give access to the page. It depends on how your security is set up. You'll need to provide more details for your case. Thank you.

    Monday, February 23, 2009 2:36 PM
  • User-532807843 posted

    okay, i need to know if the user is in NTGroups: UDD_admin, UDD_assigner or UDD_approver.. does this help?

    Monday, February 23, 2009 3:54 PM
  • User1191518856 posted

    Well, then you're almost there already. In your code, you have a loop which iterates over the groups that the current user is member of. You can add code in that loop to check if the name of the group is any of the three and then return true. If none of these groups are found, return false. Good luck!

    Thursday, February 26, 2009 3:34 AM