Get Users Groups in asp.net

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to retrieve the a users groups from active directory thru asp.net
using windows authentication. I am working on a internal website that will
use AD for its security. I already know the user via
WindowsIdentity.GetCurrent() but I can't figure out how to get the users
groups without prompting the user for the password again.
 
¤ I am trying to retrieve the a users groups from active directory thru asp.net
¤ using windows authentication. I am working on a internal website that will
¤ use AD for its security. I already know the user via
¤ WindowsIdentity.GetCurrent() but I can't figure out how to get the users
¤ groups without prompting the user for the password again.

See if the following helps:

Public Function GroupMembershipLDAP()

Dim RootDSE As New DirectoryServices.DirectoryEntry("LDAP://RootDSE")
Dim DomainDistinguishedName As String = RootDSE.Properties("DefaultNamingContext").Value
Dim ADEntry As New DirectoryServices.DirectoryEntry("LDAP://" & DomainDistinguishedName)
Dim ADSearch As New System.DirectoryServices.DirectorySearcher(ADEntry)

Dim ADSearchResult As System.DirectoryServices.SearchResult
ADSearch.PropertiesToLoad.Add("memberOf")
ADSearch.Filter = ("(samAccountName=" &
System.Security.Principal.WindowsIdentity.GetCurrent.Name.Split("\"c)(1) & ")")
ADSearch.SearchScope = SearchScope.Subtree
Dim UserFound As SearchResult = ADSearch.FindOne()
Dim PropertyCount As Integer = UserFound.Properties("memberOf").Count
If Not IsNothing(UserFound) Then
Dim PropertyCounter As Integer
Dim GroupDistinguishedName As String
Dim MemberOf as String
For PropertyCounter = 0 To PropertyCount - 1
GroupDistinguishedName = CType(UserFound.Properties("memberOf")(PropertyCounter),
String)
Console.WriteLine(GroupDistinguishedName.ToString)
Next
End If

End Function


Paul
~~~~
Microsoft MVP (Visual Basic)
 
Back
Top