Re: Active Directory - Get groups assigned to a user
- From: "Joe Kaplan \(MVP - ADSI\)" <joseph.e.kaplan@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 8 Mar 2006 14:59:41 -0600
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
.
- References:
- Active Directory - Get groups assigned to a user
- From: Chris Davoli
- Active Directory - Get groups assigned to a user
- Prev by Date: Re: Socket Server with Encryption help
- Next by Date: Re: setting permissions / trusting company via certificate?
- Previous by thread: Active Directory - Get groups assigned to a user
- Next by thread: Need help
- Index(es):
Relevant Pages
|