开发者

Updating an AD UserPrincipal that has been extended with custom properties [duplicate]

This question already has an answer here: Adding address information to active directory users (1 answer) Closed 4 years ago.

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);  
} 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜