-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: Arian_Intellect
Message 2 in Discussion
Hi Suhas,
Here is a article
In this article we're going to provide a quick example of accessing Active
Directory using the System.DirectoryServices of .Net. In previous articles we
went over using ADSI to make calls to Active Directory in your ASP or Windows
Scripting Host application. Using the System.DirectoryServices class you can
accomplish the same thing in your .Net applications.
Imports System
Imports System.Security.Principal
Imports
System.DirectoryServices
Imports System.Web
Public Class ActiveDirectory
In the following function we will pass the Sam account name to the function.
This can be obtained by reference the Context.User.Indentity.Name object in
Net. or by referring to the Request.Servervariables("LOGON_USER") object. The
second value passed to the function is the property of the user class in Active
Directory that you want to get a value of.
Public Function GetUserInfo(ByVal inSAM As String, ByVal inType As String) As String
Try
Dim sPath As
String = "LDAP://yourdomainpath.com/DC=yourdomainpath,DC=com"
Dim
SamAccount As String = Right(inSAM, Len(inSAM) -
InStr(inSAM, "\"))
Dim myDirectory As New DirectoryEntry(sPath, "Enterprise Admin", "Password") 'pass the
user account and password
for your Enterprise admin.
Dim mySearcher
As New
DirectorySearcher(myDirectory)
Dim mySearchResultColl
As
SearchResultCollection
Dim mySearchResult
As
SearchResult
Dim myResultPropColl As ResultPropertyCollection
Dim
myResultPropValueColl As
ResultPropertyValueCollection
'Build
LDAP query
mySearcher.Filter =
("(&(objectClass=user)(samaccountname=" & SamAccount &
"))")
mySearchResultColl =
mySearcher.FindAll()
'I expect only one
user from search result
Select Case
mySearchResultColl.Count
Case 0
Return "Null"
Exit Function
Case Is > 1
Return "Null"
Exit Function
End Select
'Get the search result from
the collection
mySearchResult =
mySearchResultColl.Item(0)
'Get the Properites, they
contain the usefull info
myResultPropColl = mySearchResult.Properties
'displayname,
mail
'Retrieve from the properties collection the display
name and email of the user
myResultPropValueColl = myResultPropColl.Item(inType)
Return CStr(myResultPropValueColl.Item(0))
Catch ex As System.Exception
'do some error return here.
End Try
End Function
Here we will just create some variables and populate them with the call to
the GetUserInfo function by passing the user account and name of the property we
want to get.
Dim sEmail As String = GetUserInfo(UserAccount, "mail")
Dim sFirstName As String = GetUserInfo(UserAccount,
"givenName")
Dim
sLastName As String = GetUserInfo(UserAccount,
"sn")
Dim sCity
As String = GetUserInfo(UserAccount,
"l")
Dim sState
As String = GetUserInfo(UserAccount,
"st")
Dim
sStreetAddress As
String =
GetUserInfo(UserAccount, "streetAddress")
Dim sPostalCode As String = GetUserInfo(UserAccount,
"postalCode")
Dim
sPhone As String = GetUserInfo(UserAccount,
"telephoneNumber")
Dim
sCountry As String = GetUserInfo(UserAccount,
"co")
::
::
::
::
End Class
You can use this code as a starting point for obtaining information on users
in your Active Directory domain.
Furthur artcles can be viewed at
http://www.123aspx.com/directory.aspx?dir=131
HTH
Shaju Thomas
e-Cosmos Technologies Ltd.,
Mail: [EMAIL PROTECTED]
Phone(Off)
: 51217038/39 Extn: 132
Mobile: +91 98455 21794
----- Original Message -----
From:
DotNetLearner
To: BDOTNET
Sent: Thursday, October 23, 2003 3:32
PM
Subject: Getting User details from Active
Directory
-----------------------------------------------------------
New
Message on
BDOTNET
-----------------------------------------------------------
From:
DotNetLearner
Message 1 in Discussion
Hi, Could
any one give some tips on how to read User Details from an Active Directory
? Thanks in Advance Suhas
-----------------------------------------------------------
To
stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw
Need
help? If you've forgotten your password, please go to Passport Member
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For
other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If
you do not want to receive future e-mail from this MSN group, or if you
received this message by mistake, please click the "Remove" link below. On the
pre-addressed e-mail message that opens, simply click "Send". Your e-mail
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you received
this message by mistake, please click the "Remove" link below. On the pre-addressed
e-mail message that opens, simply click "Send". Your e-mail address will be deleted
from this group's mailing list.
mailto:[EMAIL PROTECTED]