Re: Active Directory - Get groups assigned to a user



Like I said before, there is no reason to do this with LDAP if you don't
have to.

For example, you could do this:

WindowsIdentity wi = (WindowsIdentity) Context.User.Identity;
foreach (IdentityReference ir in wi.Groups)
{
//....
}

If you really want to expand a user's groups via LDAP, don't look at the
groups, look at the user. The user's tokenGroups attribute contains a
user's full security group membership. Ryan has a nice sample on his blog
that discusses how to read this:

www.dunnry.com/blog

Joe K.

"Chris Davoli" <ChrisDavoli@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E4453FD1-5DDA-45FA-A75E-17EE67E2184A@xxxxxxxxxxxxxxxx
I'm just trying to look up what groups are assigned to a specific user
(currently logged in user) using Active Directory. I'm getting the error
below. What do I need to do?

Here is my code:
public DirectoryEntry GetDirectoryEntry()
{
DirectoryEntry deGroup = new
DirectoryEntry("LDAP://XX.XXX.X.XX/CN=ClinNutUser;DC=XXXXXXXXX.Med";);


foreach(object oMember in deGroup.Properties["member"])
{
Trace.Write(oMember.ToString());

}
return deGroup;
}


Server Error in '/BN' Application.
--------------------------------------------------------------------------------

The directory service is unavailable
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about
the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: The
directory service is unavailable

Source Error:


Line 233:
Line 234:
Line 235: foreach(object oMember in deGroup.Properties["member"])
Line 236: {
Line 237: Trace.Write(oMember.ToString());


Source File: c:\inetpub\wwwroot\bn\userinput.aspx.cs Line: 235

Stack Trace:


[COMException (0x8007200f): The directory service is unavailable]
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
System.DirectoryServices.DirectoryEntry.Bind()
System.DirectoryServices.DirectoryEntry.get_AdsObject()
System.DirectoryServices.PropertyValueCollection.PopulateList()
System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry
entry, String propertyName)
System.DirectoryServices.PropertyCollection.get_Item(String
propertyName)
BN.UserInput.GetDirectoryEntry() in
c:\inetpub\wwwroot\bn\userinput.aspx.cs:235
BN.UserInput.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\bn\userinput.aspx.cs:191
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2032;
ASP.NET
Version:1.1.4322.2032
--
Chris Davoli



.



Relevant Pages

  • RE: [PHP] RE: Address book - LDAP or MySQL?
    ... I didn't say LDAP was a database. ... to set up a network address book of some kind. ... A directory service is a software application - or a set of applications ... book using MySQL and access it with PHP's library of MySQL functions. ...
    (php.general)
  • Re: [PHP] RE: Address book - LDAP or MySQL?
    ... since Timothy is already using MySQL that sounds like a great place for the ... So let me see if i can draw LDAP into the equation. ... graphical interface via PHP, but he wants to allow people to query the ... A directory service is a software application - or a set of applications ...
    (php.general)
  • Re: The specified Directory Service has denied access
    ... The thing is I do not wish to enable anonymous ldap binding (unless I have ... Allow anonymous LDAP binding to an ADAM instance ... "The specified Directory Service has denied access. ...
    (microsoft.public.windows.server.active_directory)
  • Re: company-wide address book?
    ... >If you mean some sort of directory service that will fill in the name of ... >Netscape Mail client and Netscape's Directory Service (an implementation ... >of LDAP) will work. ... If you have divergent email clients, ...
    (comp.unix.solaris)
  • Re: company-wide address book?
    ... >If you mean some sort of directory service that will fill in the name of ... >Netscape Mail client and Netscape's Directory Service (an implementation ... >of LDAP) will work. ... If you have divergent email clients, ...
    (comp.os.linux.misc)

Quantcast