Reading active directory user id

I have a requirement to retreive all the active directory users when a specific user group isentered.
And I have the following code that does that. But my problem is it retreives everything but the user id.
How do I get only the user id? Please help.

    Public Function GetADGroupUsers(ByVal groupName As String) As ArrayList

        Dim result As SearchResult

        Dim search As DirectorySearcher = New DirectorySearcher()
        search.Filter = String.Format("(cn={0})", groupName)
        search.PropertiesToLoad.Add("member")
        result = search.FindOne()

        Dim userNames As ArrayList = New ArrayList()
        If result Is Nothing Then
        Else
            For counter As Integer = 0 To result.Properties("member").Count - 1
                Dim user As String = CType(result.Properties("member")(counter), String)
                userNames.Add(user)
            Next
        End If
        Return userNames

    End Function

0
coolvaas1
1/13/2007 2:28:23 AM
asp.net.security 27051 articles. 1 followers. Follow

2 Replies
636 Views

Similar Articles

[PageSpeed] 8

Refer to my thread here: http://forums.asp.net/thread/1528969.aspx

Hope this helps.

 Jae.


jae.lee@jaeleeandco.com
0
jae
1/13/2007 3:18:40 AM

It works great, is there any way to get the users for a specific user group. This code gives me all users.

Dim oroot As DirectoryEntry = New DirectoryEntry("LDAP://YOURACTIVEDIRECTORY", "USERNAME-ADMIN, "PASSWORD")
        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 & ":" & result.GetDirectoryEntry.Properties("userPrincipalName").Value)
            End If
        Next

0
coolvaas1
1/24/2007 3:10:13 PM
Reply:

Similar Artilces:

Reading active directory user id for a user group
I need to write a function that accepts active directory user group and return all the users belong to that group. My function so far returns user fist name, last name and so on except userid. I am not sure how to retreive that.  Dim path As String = "LDAP://asd.dev.com"        Dim entry As DirectoryEntry = New DirectoryEntry(path)        Try            'Dim native As Object = entry.NativeObject             ...

Understanding the Security Implication of Active Directory Default Settings Part II of An Audit of Active Directory Security
http://www.securityfocus.com/focus/microsoft/aads2.html -- Regard: Joh@nnes� 1216771 Ont.Inc. "Nothing is more damaging to a new truth than an old error" ...

Get a User ID from Active Directory
Hello,  I have been searching through the forums and came across this code..  All i want to do is to find who is loggin when when the open my company's intranet.  Only problem is that we use a thin desktop client.  We do have windows login, but they might not be the person logging onto the intranet.  Since they have to log in to Citrix before then can access the intranet.  Can this code be edited for Citrix??  Rich 1    /// <summary>2    /// Gets the windows login for the currently logged in user in the client com...

Retrieve active directory id in .net
Hi, can you please help me to Retrieve active directory id in .net (in Domain\Username format) assuming you are using authentication Mode="windows" ..User.Identity.Name or WindowsIdentity.GetCurrent().Name/GuruBhai I've already tried it, but it asks me ID and password everytime I open the page, I dont want to authenticate the user by using domain username and password but I just want to display domainusername on the screen without being asked for the password but you have windows authentication set right?what are your IIS and web.config settings?please provide more det...

reading user name from active directory
Hi , I am preparing an intranet application where in which all the users will logged onto their systems. So is there anyway i can see the username who is accessing my web application.~ Remember To Mark The Posts Which Helped You As The ANSWER ~ Crewe2008: Hi , I am preparing an intranet application where in which all the users will logged onto their systems. So is there anyway i can see the username who is accessing my web application. I use this in one of my intranet applications and it returns what I need.  I would test it in a label control and see if it works for...

How to check the username with active directory and fetch the user details from the active directory?
I have a textbox with a submit button.When the admin types the username in the textbox and submits it has to check with active directory and fetch the firstname and last name of the user entered inthe textbox.How will i do this one.Code is appreciated. you will find lot of samples if you search for "ActiveDirectory using .NET" but here is a verysimple code and it works too:-) strLANID = "ADDomainName\user"           Dim dservices As New System.DirectoryServices.DirectoryEntry        ...

Is there a way to authenticate Active Directory users from multiple Active Directory Domains
Is there a way to authenticate Active Directory users from multiple Active Directory Domains in ASP.NET Application using C# or VB.NET?Suppose I have a LoginId "user1" from one of the three Active Directory Domains how can I authenticate it?I have two Active Directory domains. I can authenticate from the Active Directory Domain where my current system Account is logged in. But I can not authenticate from other Active Directory Domains. Actually I have 2 Active Directory domains in my LAN.Kamran ShahidSr. Software Engineer(MCP,MCAD.net,MCSD.net,MCTS,MCPD.net[web])Netprosys Inc.ww...

Net::LDAP, Active Directory and Disabled Users
------_=_NextPart_001_01C386CB.502F3B30 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I've been trying to write a simple perl script that will query the = active directory via LDAP and give me a list of email addresses for disabled = users (eg, addresses we don't want to accept email for anymore). I found a = website or two that suggested I use the following as my filter: (&(objectCategory=3Dperson)(userAccountControl:1.2.840.113556.1.4.803:=3D= 2)) I was beginning to think these websites were wrong as whene...

updating active directory user profiles with.net
hi all; i'am using this forum first time. i like this very much. i have a questions abut active directory with .net. so i wanna updating user profiles using asp.net. for example there is a computer laboratuar , a windows 2003 server and a web page that using active directory accounts to authenticate system. for example me. i wanna updating my profile using web page , if i authenticated system. i hope, i can tell my questions:) 'cause my english not good. thanks.Mesut KOSUCUSoftware Engineer...

User Account to read Active Directory for authentication
Must the account be a Domain Admin to read active directory information to authenticate and retrieve user properties?  Can I create an account with explicit permissions to do that?Thanks,Jim...

Trying to check Active Directory for a user ID
I used the LdapAuthentication class show on msdn at http://msdn2.microsoft.com/en-us/library/ms180890.aspx This is for a webapp i'm creating for someone to add a user to an application security db.  It's just giving users access to applications.  I just want to verify that the user id being entered, is in AD.  I tried modifying the IsAuthenticated method given, to just take parameters of domain and username, excluding password.  When I get to the line to bind the native adsobject, I get this error:  "The specified directory service attribute or value does not exist"...

Retrieving User ID and Password from Active Directory
I am working on a web form using vb.net When a user browses to my page, the active directory authentication window will prompt them first. Then if they are authenticated they are forwarded to my login page. They reason I need a login page is to get the user credentials for DB2 connections. My question: Is there a way I can get the User ID and Password from active directory and use it for my DB2 connection? That will eliminate the need of login twice. Thank you all I don't believe you can get a password back, even as an admin. Just like you can only reset a pass as a...

.Net Form To Register New Users For Active Directory
Is it possible to build a form using VB.Net or C#.Net, that will allow users to create their own account for Active Directory via Internet Explorer? Yes, subject to appropriate permissions and correct code. Check out this article for details: http://www.15seconds.com/issue/020730.htm ...

necessary user rights for reading information from active directories
hey there!i'm currently working at a project, where i need to read information from active directories accounts. i already know how this is possible and how it works. but at all the examples on the internet they are always using the admin account for connecting to the active directory server. now that i only need to read information i'm wondering if this would be possible with a different account whose rights would be limited.and if possible, which rights would this account need?thanks in advance,andreas Any normal domain account has the right to read the directory and update a few of...

Web resources about - Reading active directory user id - asp.net.security

Wikipedia:Quick directory - Wikipedia, the free encyclopedia
This page is a handy directory to various locations of interest in Wikipedia. Only dynamic pages should be listed here, no policy pages etc. ...

Wikipedia:WikiProject Council/Directory - Wikipedia, the free encyclopedia
Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc. , a non-profit organization.

Business Directory Listings: Eight Smart Tips for You to Get Started
If you are considering a business directory listing for your small business, congratulations – you are on the right track. Local SEO, local customers, ...

LinkedIn Lookup iOS app aims to replace your company’s awful intranet employee directory
... continue reading at 9to5Mac . What do you think? Discuss "LinkedIn Lookup iOS app aims to replace your company’s awful intranet employee directory" ...

Atlas Partner Directory Launched
... just for Facebook and Instagram –advertising platform Atlas has one, as well. On that note, Atlas Tuesday introduced the Atlas Partner Directory ...

Slack announces App Directory store
... create more apps for the store, and a new framework called Botkit which should simplify the process of creating apps. The Slack App Directory, ...

The British Library’s ‘Save Our Sounds’ Program Creates Directory of UK Sound Collections
The long-feared deterioration of the world's sound collections is a coming to a head with the British Library's last-ditch initiative called ...

Researchers show how to steal Windows Active Directory credentials from the Internet
... showed at the Black Hat security conference. The attack, called an SMB relay, causes a Windows computer that's part of an Active Directory ...

Researchers find way to steal Windows Active Directory credentials from the Internet
The technique could enable attackers to attack Windows servers hosted in the cloud

Slack's App Directory proves it's more than just a chatroom
... are about to get a little easier to find and integrate within your team and over 160 of them live within the company's new Slack App Directory. ...

Resources last updated: 12/26/2015 4:04:21 AM