10-30-2006, 11:09 AM
Join Date: Nov 2005
I am writing an asp.net application using Visual Studio 2003.
I need this webpage to recognise the person loggin in. I have done a User.Identity.Name but need to reference that against the Active Directory. I have this code, which works when run on my own laptop but as soon as I publish this to the webserver it doesn't bring anything back..
#Region "Active Directory"
'This is to connect to the Active Directory
Public Shared Function GetUserInfo(ByVal inSAM As String, ByVal inType As String) As String
Dim sPath As String = "LDAP://sv30/dc=trans,dc=com"
Dim SamAccount As String = Microsoft.VisualBasic.Right(inSAM, Len(inSAM) - InStr(inSAM, "\"))
'This is variable myDirectory as a New DirectoryEntry of the Active Directory
Dim myDirectory As New DirectoryEntry(sPath)
'This is a searcher which searches the myDirectory Variable (i.e. Active Directory)
Dim mySearcher As New DirectorySearcher(myDirectory)
'This is the search result collection to get results together
Dim mySearchResultColl As SearchResultCollection
'This is the search Results
Dim mySearchResult As SearchResult
'These are the properties of the results collection
Dim myResultPropColl As ResultPropertyCollection
'These are the values of the properties of the results collection
Dim myResultPropValueColl As ResultPropertyValueCollection
'Build LDAP Query
mySearcher.Filter = ("(&(objectclass=user)(samaccountname=" & SamAccount & "))")
mySearchResultColl = mySearcher.FindAll()
'I expect only one user from each search result
Select Case mySearchResultColl.Count
Case Is > 1
'Get the search result from the collection
mySearchResult = mySearchResultColl.Item(0)
'Get the properties
myResultPropColl = mySearchResult.Properties
'Display name, mail
'Retrieve from the properties collection the display name and email of the user
myResultPropValueColl = myResultPropColl.Item(inType)
Catch ex As Exception
Am I doing something wrong?