locked
get all users in specific NTGroup RRS feed

  • Question

  • User-532807843 posted

    I want to know if there is a way in C# to return all users within a specific NTGroup in active directory? say for example, i want all the users in the "Domain\UDD_admin" group.

     is this possible?

     any help?

     

    Thank you

    Tuesday, February 24, 2009 4:21 PM

Answers

  • User-647234374 posted

    It's actually even easier if all you want to do is check if a logged in user is in a specific group.

            Group name:
            <asp:TextBox ID="txtGroup" runat="server"></asp:TextBox><br />
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Check it" /><br />
            <asp:Label ID="lblGroup" runat="server"></asp:Label></div>
    
     

    using System.Security.Principal;

            WindowsPrincipal principal = new WindowsPrincipal(System.Web.HttpContext.Current.Request.LogonUserIdentity);
            bool b = principal.IsInRole(txtGroup.Text);
            lblGroup.Text = principal.Identity.Name + " in role? " + b.ToString();
    
     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 25, 2009 2:31 PM

All replies

  • User-532807843 posted

    Thanks for the code, however it showed me how to get the users membership groups, but what if i want to supply it with specific group>? i want to check to see if the current logged in user is in a specific group and if so, return the group name if it matches. does this make sense? say for instance the group name is UDD_admin

    public ArrayList groups()

    {

    ArrayList groups = new ArrayList();

    foreach (System.Security.Principal.IdentityReference group in

    System.Web.HttpContext.Current.Request.LogonUserIdentity.Groups)

    {

    groups.Add(group.Translate(typeof

    (System.Security.Principal.NTAccount)).ToString());

    }

    return groups;

    }

     

    this grabs ALL memberships, but i want the membership group that user is in to access the page since im using windows authentication, do i just do an if statement? if UserInRole == ""  then lblGroup = ""?

     

    thanks

    Wednesday, February 25, 2009 1:08 PM
  • User-647234374 posted

    It's actually even easier if all you want to do is check if a logged in user is in a specific group.

            Group name:
            <asp:TextBox ID="txtGroup" runat="server"></asp:TextBox><br />
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Check it" /><br />
            <asp:Label ID="lblGroup" runat="server"></asp:Label></div>
    
     

    using System.Security.Principal;

            WindowsPrincipal principal = new WindowsPrincipal(System.Web.HttpContext.Current.Request.LogonUserIdentity);
            bool b = principal.IsInRole(txtGroup.Text);
            lblGroup.Text = principal.Identity.Name + " in role? " + b.ToString();
    
     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 25, 2009 2:31 PM