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
精彩评论