Solved

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

Posted on 2013-12-05
6
403 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 250 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
in Dot net,lastest version of MVC 3 24
tutorial for ebay api 3 34
asp.net input html code have it display the content 2 11
parsing JSON help 1 9
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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…

770 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