Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I display the Active Directory Groups in a List Box?

Posted on 2013-12-05
6
Medium Priority
?
431 Views
Last Modified: 2013-12-05
Here are my events:

<%@ Import Namespace="System.DirectoryServices" %>

<script runat="server">

 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;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        dGroups.DataSource = Groups();
        dGroups.DataBind();
    }

Open in new window


My question is - how do I display the results in a list box?  I can not seem to get all my settings/preferences correct:

<asp:DropDownList ID="dGroups" runat="server"  DataTextField="ArrayList" DataValueField="Department" onselectedindexchanged="" 
        AutoPostBack="True" AppendDataBoundItems="True">
        <asp:ListItem Value="0">Select</asp:ListItem>
      </asp:DropDownList>

Open in new window

0
Comment
Question by:programmher
  • 3
  • 3
6 Comments
 
LVL 22

Accepted Solution

by:
plusone3055 earned 1000 total points
ID: 39698990
0
 

Author Comment

by:programmher
ID: 39699036
So, if I want the Active Directory Groups to display in a listbox in the body of my form, I do not need to reference the event?
0
 
LVL 22

Expert Comment

by:plusone3055
ID: 39699044
its not necessary :)
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:programmher
ID: 39699109
Ok.  I am working on including this on my form.
0
 
LVL 22

Expert Comment

by:plusone3055
ID: 39699121
Excellent :)
Enjoy and if it works for you please award points.
Happy Coding
0
 

Author Comment

by:programmher
ID: 39699136
I have added the code to my form.  No errors, but the list box/drop down list with the Active Directory groups is not displaying on my form.  Here is what I added:
 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;
    }
    public ArrayList AttributeValuesMultiString(string attributeName,
     string objectDn, ArrayList valuesCollection, bool recursive)
    {
        DirectoryEntry ent = new DirectoryEntry(objectDn);
        PropertyValueCollection ValueCollection = ent.Properties[attributeName];
        IEnumerator en = ValueCollection.GetEnumerator();

        while (en.MoveNext())
        {
            if (en.Current != null)
            {
                if (!valuesCollection.Contains(en.Current.ToString()))
                {
                    valuesCollection.Add(en.Current.ToString());
                    if (recursive)
                    {
                        AttributeValuesMultiString(attributeName, "LDAP://" +
                        en.Current.ToString(), valuesCollection, true);
                    }
                }
            }
        }
        ent.Close();
        ent.Dispose();
        return valuesCollection;
    }

    public ArrayList Groups(string userDn, bool recursive)
    {
        ArrayList groupMemberships = new ArrayList();
        return AttributeValuesMultiString("memberOf", userDn,
            groupMemberships, recursive);
    }

Open in new window

0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question