PC Review


Reply
Thread Tools Rate Thread

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

 
 
Jim in Arizona
Guest
Posts: n/a
 
      6th Mar 2008
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



 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      6th Mar 2008
On Mar 6, 6:51*pm, "Jim in Arizona" <tiltow...@hotmail.com> wrote:
> 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
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
AUTH_USER blank when using HttpContext.Current JP Microsoft Dot NET 0 22nd Oct 2008 10:22 PM
AUTH_USER and roles drengot Microsoft ASP .NET 1 13th Oct 2008 07:45 PM
AUTH_USER & LOGON_USER server variables Mark Rae Microsoft ASP .NET 0 26th Jul 2006 11:16 AM
auth_user is lying ? z f Microsoft ASP .NET 2 30th Oct 2005 04:00 PM
AUTH_USER & User.Identity.Name? =?Utf-8?B?RGF2ZQ==?= Microsoft ASP .NET 4 1st Oct 2004 09:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:15 PM.