我想从用户那里获取 Active Directory 属性并且我想使用System.DirectoryServices.AccountManagement
.
my code:
public static void GetUserProperties(string dc,string user)
{
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, dc);
UserPrincipal u = UserPrincipal.FindByIdentity(ctx, user);
string firstname = u.GivenName;
string lastname = u.Surname;
string email = u.EmailAddress;
string telephone = u.VoiceTelephoneNumber;
...//how I can get company and other properties?
}
您可以转换到 DirectoryServices 命名空间以获取所需的任何属性。
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, dc);
UserPrincipal u = UserPrincipal.FindByIdentity(ctx, user);
string firstname = u.GivenName;
string lastname = u.Surname;
string email = u.EmailAddress;
string telephone = u.VoiceTelephoneNumber;
string company = String.Empty;
...//how I can get company and other properties?
if (userPrincipal.GetUnderlyingObjectType() == typeof(DirectoryEntry))
{
// Transition to directory entry to get other properties
using (var entry = (DirectoryEntry)userPrincipal.GetUnderlyingObject())
{
if (entry.Properties["company"] != null)
company = entry.Properties["company"].Value.ToString();
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)