Checking the AUTH_USER against AD (and looking to see which group they're in)

J

Jim in Arizona

I've been searching a lot for a simple example to search for a single
account name in active directory but have been unable to find what I'm
looking for. I did find an exmple (that worked) that pulls out all names in
the AD but that isn't what I need.

My goal is to check the AD for a username that matches
Request.ServerVariables("AUTH_USER"). That would be the first step. The next
step would be to see what security or distribution group they're in (in AD)
and redirect them based on that information.

This is the code that searches the entire directory and returns EVERYONE. I
suppose this would be useful only if I knew how to search the list for a
single name.

======================================================

Dim oroot As DirectoryEntry = New
DirectoryEntry("LDAP://corp.commspeed.net")
Dim osearcher As DirectorySearcher = New DirectorySearcher(oroot)
Dim oresult As SearchResultCollection
Dim result As SearchResult

osearcher.Filter = "(&(objectCategory=person))" ' search filter
osearcher.PropertiesToLoad.Add("cn") ' username
'osearcher.PropertiesToLoad.Add("name") ' full name
'osearcher.PropertiesToLoad.Add("givenname") ' firstname
'osearcher.PropertiesToLoad.Add("sn") ' lastname
'osearcher.PropertiesToLoad.Add("mail") ' mail
'osearcher.PropertiesToLoad.Add("initials") ' initials
'osearcher.PropertiesToLoad.Add("ou") ' organizational unit
'osearcher.PropertiesToLoad.Add("userPrincipalName") ' login name
'osearcher.PropertiesToLoad.Add("distinguishedName") ' distinguised
name
oresult = osearcher.FindAll

For Each result In oresult
If Not result.GetDirectoryEntry.Properties("sn").Value Is
Nothing Then
' writes specific values retrieved from above - this is just
a sample.
Response.Write(result.GetDirectoryEntry.Properties("cn").Value
& "<br />")
End If
Next

======================================================

Is there a way to rework that code above for my specific usage or is there
another route I need to take?

TIA,
Jim
 
G

Guest

I've been searching a lot for a simple example to search for a single
account name in active directory but have been unable to find what I'm
looking for. I did find an exmple (that worked) that pulls out all names in
the AD but that isn't what I need.

My goal is to check the AD for a username that matches
Request.ServerVariables("AUTH_USER"). That would be the first step. The next
step would be to see what security or distribution group they're in (in AD)
and redirect them based on that information.

This is the code that searches the entire directory and returns EVERYONE. I
suppose this would be useful only if I knew how to search the list for a
single name.

======================================================

Dim oroot As DirectoryEntry = New
DirectoryEntry("LDAP://corp.commspeed.net")
        Dim osearcher As DirectorySearcher = New DirectorySearcher(oroot)
        Dim oresult As SearchResultCollection
        Dim result As SearchResult

        osearcher.Filter = "(&(objectCategory=person))" ' search filter

Use

(&(objectCategory=Person)(cn=user_name_here))

or

(&(objectCategory=Person)(sAMAccountName=user_name_here))

Hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top