Active directory 从Windows标识中仅获取名字

Active directory 从Windows标识中仅获取名字,active-directory,environment,authentication,windows-identity,directoryentry,Active Directory,Environment,Authentication,Windows Identity,Directoryentry,有没有办法在WindowsIdentity中只获取用户的名字? 现在我通过以下代码获取全名: DirectoryEntry userEntry = new DirectoryEntry("WinNT://" + domain + "/" + userName + ",User"); string fullName = (string)userEntry.Properties["fullname"].Value; 但我想把名字和姓氏分开 现在我使用的是split“”,但有些用户有两个或两个以上的

有没有办法在WindowsIdentity中只获取用户的名字? 现在我通过以下代码获取全名:

DirectoryEntry userEntry = new DirectoryEntry("WinNT://" + domain + "/" + userName + ",User");
string fullName = (string)userEntry.Properties["fullname"].Value;
但我想把名字和姓氏分开

现在我使用的是split“”,但有些用户有两个或两个以上的名字和姓氏,我无法处理这个问题


谢谢。

因为我假设您想要两个不同的属性:名字和姓氏。 如果是这样,那么您可以使用FirstName和姓氏属性

string firstName = (string)userEntry.Properties["firstname"].Value;
string surname = (string)userEntry.Properties["surname"].Value;

希望这有帮助

是否可以切换到LDAP:provider而不是WinNT:?正如您从完整用户对象列表中看到的,该对象有FirstName和LastName,但WinNT提供程序不支持它们。如何获取属性?您不能在路径中将WinNT替换为LDAP,它什么也不提供。你能写一个如何使用这个的答案吗?