开发者

Unauthorized Access Exception on UserPrincipal.Save()

i am running the following

  static void UpdateEmployeeID(string userName, string id)
    {
       PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
        bool val = ctx.ValidateCredentials("myusername", "mypassword");

        UserPrincipal user = User开发者_如何学PythonPrincipal.FindByIdentity(ctx, userName);
        if (user != null)
        {
            user.EmployeeId = id;
            user.Save(ctx);
        }
     }

When it runs I get an Unauthorized Access Exception on the User.Save(ctx) The user name and password are correct and ctx.ValidateCredentials returns true and the username and password has rights to make changes to AD

how can i get this to work?


You should specify your username and password when you create PrincipalContext.

PrincipalContext.ValidateCredentials doesn't persist your given username password into the PrincipalContext

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜