rosmiq
10-30-2006, 10:09 AM
Hi,
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
Try
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 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 properties
myResultPropColl = mySearchResult.Properties
'Display name, 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 Exception
Console.WriteLine(True)
End Try
End Function
#End Region
Am I doing something wrong?
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
Try
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 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 properties
myResultPropColl = mySearchResult.Properties
'Display name, 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 Exception
Console.WriteLine(True)
End Try
End Function
#End Region
Am I doing something wrong?