C#将用户更新为AD throws'为目录服务指定的属性语法无效。

时间:2017-11-10 12:39:48

标签: c# active-directory

更新某些字段不起作用,而其他字段则不起作用。即使旧值和新值是字符串,也会抛出异常。

UserPrincipal user = GetUser();
var userEntry = user.GetUnderlyingObject() as DirectoryEntry;

// When creating user this kind of stuff works
userEntry.Properties["pager"].Add("12345");
user.Save();

// When updating this doesn't work for attributes
// E.g. mobile has value "+12 34 567 89 01" of type String
userEntry.Properties["mobile"].Value = "0345678901"; // not ok
user.Save();
// Exception 'The attribute syntax specified to the directory service is invalid.'

// also not ok
userEntry.Properties["mobile"].RemoveAt(0);
userEntry.Properties["mobile"].Add("0345678901");
user.Save();

0 个答案:

没有答案