Updating an AD UserPrincipal that has been extended with custom properties [duplicate]
I'm stuck with AD again. Can anyone please point me in the direction of an example of how to update a UserPrincipal (C#) that has been extended using the [DirectoryProperty("Title")] style properties?
I can create the user fine, but when I retrieve him, he is a UserPrincipal again, and not my extended class. I've tried constructing my extended class like this
ADUserClassExtensions userExt = new ADUserClassExtensions(ctx, userOfInterest.SamAccountName, "******", true);
Hoping that it would let me set the properties 开发者_如何学JAVAand then save it. But it (rightly) complains that the user already exists because I am doing a Save() ,and I can't see an Update() method on there.
What's the recommended way to do this? Googled a bit and can't find anything.
Many thanks
In the extending class:
public static new ADUserClassExtensions GetPrincipalByIdentity(PrincipalContext ctx, string identityValue)
{
return (ADUserClassExtensions) Principal.FindByIdentityWithType(ctx, typeof(ADUserClassExtensions), identityValue);
}
精彩评论