开发者

Unauthorized Access Exception on UserPrincipal.Save()

开发者 https://www.devze.com 2023-02-10 07:10 出处:网络
i am running the following static void UpdateEmployeeID(string userName, string id) { PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

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

精彩评论

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