- : , .NET 3.5, System.DirectoryServices, System.DirectoryServices.AccountManagement:
public UserPrincipal GetManager(PrincipalContext ctx, UserPrincipal user)
{
UserPrincipal result = null;
if (user != null)
{
DirectoryEntry dirEntryForUser = user.GetUnderlyingObject() as DirectoryEntry;
if (dirEntryForUser != null)
{
if (dirEntryForUser.Properties["manager"] != null)
{
string managerDN = dirEntryForUser.Properties["manager"][0].ToString();
result = UserPrincipal.FindByIdentity(ctx, managerDN);
}
}
}
return result;
}
, . :
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
UserPrincipal myself = UserPrincipal.Current;
UserPrincipal myManager = GetManager(ctx, myself);