powered by simpleCommunicator - 2.0.59     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / ASP.NET [игнор отключен] [закрыт для гостей] / Про ActiveDirectory
4 сообщений из 4, страница 1 из 1
Про ActiveDirectory
    #32896586
New_member
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Может кто нибудь знает как по имени пользователя, можно вытащить сведения пользователя (например ФИО) из ActiveDirectory
...
Рейтинг: 0 / 0
Про ActiveDirectory
    #32897204
Фотография hDrummer
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Посмотрите в сторону класса DirectorySearcher и в MSDN "Introduction to Active Directory Objects".
...
Рейтинг: 0 / 0
Про ActiveDirectory
    #32897217
Фотография hDrummer
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Ну и этот код может поможет:

Cоздаём объект DirectorySearcher для поиска пользовательской учётной записи

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
DirectorySearcher oDS = new DirectorySearcher("LPAP://dc=ВашДомен,dc=com");

oDS.Filter = "(samAccountName=<your LAN user id>");
oDS.PropertiesToLoad.Add("givenName"); // имя
oDS.PropertiesToLoad.Add("sn"); // фамилия
oDS.PropertiesToLoad.Add("initials"); // инициалы
oDS.PropertiesToLoad.Add("mail"); // e-mail

b) ищем пользователя и если найден, то отображаем информацию

DirectoryEntry deUser = oDS.FindOne();
if(deUser != null)
{
    Console.WriteLine(deUser.Properties["givenName"].Value.ToString()
+ " " + deUser.Properties["initials"].Value.ToString() + ". " +
deUser.Properties["sn"].Value.ToString() + " (" +
deUser.Properties["mail"].Value.ToString() + ")");
}
...
Рейтинг: 0 / 0
Про ActiveDirectory
    #32900631
New_member
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Делаю следующее, но кричит, что DirectoryEntry, DirectorySearcher не описаны:

Public Class ActiveDirectory
Public Shared Function GetUserInfo(ByVal inSam As String, ByVal inType As String) As String
Try
Dim sPath As String = "LDAP://youcompany.com/DC=youcompany/DC=com"
Dim SamAccount As String = Right(inSam, Len(inSam) - InStr(inSam, "\"))
Dim myDirectory As New DirectoryEntry(sPath, "domain admins", "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
End Class

Подскажите в чем ошибка?
...
Рейтинг: 0 / 0
4 сообщений из 4, страница 1 из 1
Форумы / ASP.NET [игнор отключен] [закрыт для гостей] / Про ActiveDirectory
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]