Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jim in Arizona - 06 Mar 2008 17:51 GMT
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
Alexey Smirnov - 06 Mar 2008 19:22 GMT
> 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
[quoted text clipped - 19 lines]
>
>         osearcher.Filter = "(&(objectCategory=person))" ' search filter

Use

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

or

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

Hope this helps

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.