The basic UserPrincipal
in the S.DS.AM namespace does not feature that attribute - but you can extend the user principal class and add additional attributes that you need.
Read more about it here:
Managing Directory Security Principals in the .NET Framework 3.5
(there's a section on extensibility towards the end of the article)
Here's the code:
[DirectoryRdnPrefix("CN")]
[DirectoryObjectClass("Person")]
public class UserPrincipalEx : UserPrincipal
{
// Inplement the constructor using the base class constructor.
public UserPrincipalEx(PrincipalContext context) : base(context)
{ }
// Implement the constructor with initialization parameters.
public UserPrincipalEx(PrincipalContext context,
string samAccountName,
string password,
bool enabled) : base(context, samAccountName, password, enabled)
{}
// Create the "Manager" property.
[DirectoryProperty("manager")]
public string Manager
{
get
{
if (ExtensionGet("manager").Length != 1)
return string.Empty;
return (string)ExtensionGet("manager")[0];
}
set { ExtensionSet("manager", value); }
}
// Implement the overloaded search method FindByIdentity.
public static new UserPrincipalEx FindByIdentity(PrincipalContext context, string identityValue)
{
return (UserPrincipalEx)FindByIdentityWithType(context, typeof(UserPrincipalEx), identityValue);
}
// Implement the overloaded search method FindByIdentity.
public static new UserPrincipalEx FindByIdentity(PrincipalContext context, IdentityType identityType, string identityValue)
{
return (UserPrincipalEx)FindByIdentityWithType(context, typeof(UserPrincipalEx), identityType, identityValue);
}
}
Now you can find and work with a UserPrincipalEx
class which has the .Manager
property for you to use:
UserPrincipalEx userEx = UserPrincipalEx.FindByIdentity(ctx, "YourUserName");
// the .Manager property contains the DN (distinguished name) for the manager of this user
var yourManager = userEx.Manager;