使用ASP.net CORE MVC网站中的Active Directory,
我可以获得许多用户属性,例如diplayName,emailAdress ...
但是我找不到用户部门。
获取用户信息:
UserPrincipal user = UserPrincipal.FindByIdentity(new PrincipalContext(ContextType.Domain), Environment.UserName);
但是用户没有“部门”属性。
我已经尝试过:
DirectoryEntry directoryEntry = user.GetUnderlyingObject() as DirectoryEntry;
var property = "department";
if (directoryEntry.Properties.Contains(property))
{
var dep = directoryEntry.Properties[property].Value.ToString();
}
也没有部门财产。
编辑
以下是可用的属性列表:"objectClass, cn, sn, title, description, userCertificate, givenName, distinguishedName, instanceType, whenCreated, whenChanged, displayName, uSNCreated, memberOf, uSNChanged, proxyAddresses, homeMDB, mDBUseDefaults, mailNickname, name, objectGUID, userAccountControl, badPwdCount, codePage, countryCode, badPasswordTime, lastLogon, pwdLastSet, primaryGroupID, objectSid, accountExpires, logonCount, sAMAccountName, sAMAccountType, showInAddressBook, legacyExchangeDN, userPrincipalName, objectCategory, dSCorePropagationData, lastLogonTimestamp, textEncodedORAddress, mail and Lot of msExchange"
答案 0 :(得分:3)
这对我有用(混合使用<ListBox
dd:DragDrop.IsDragSource="True"
dd:DragDrop.IsDropTarget="True"
ItemsSource="{Binding Layers}">
<ListBox.ItemTemplate>
<DataTemplate>
<ComboBox Height="25" Width="100" SelectedItem="{Binding SelectedItem}"
xmlns:s="clr-namespace:System;assembly=mscorlib">
<s:String>HELLO</s:String>
<s:String>BONJOUR</s:String>
<s:String>NIHAO</s:String>
</ComboBox>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
和AccountManagement
):
DirectoryServices
这需要以下var ad = new PrincipalContext(ContextType.Domain, DOMAIN);
var u = new UserPrincipal(ad) {SamAccountName = Environment.UserName};
using (var search = new PrincipalSearcher(u))
{
var user = (UserPrincipal) search.FindOne();
DirectoryEntry dirEntry = (DirectoryEntry)user.GetUnderlyingObject();
string dept = dirEntry.Properties["Department"].Value.ToString();
Console.WriteLine(dept);
}
:
using
答案 1 :(得分:0)
搜索员工单位
使用价值
Department = directoryEntry.Properties["subdivision"].Value as string,