我尝试在AD中创建用户。
现在,我收到错误:
0000052D:SvcErr:DSID-031A1248,问题5003(WILL_NOT_PERFORM),数据0
服务器不愿意处理请求
翻译:El servidor no puede procesar la solicitud。
我的实际遗留代码(主要片段):
SearchResult ret = searcher.FindOneReturningDirectorySearchResult();
if (ret == null)
throw new ObjectNotFoundException("group", searcher.GetFilter());
using (DirectoryEntry parent = ret.GetDirectoryEntry())
{
parent.RefreshCache();
using (DirectoryEntry newUser = parent.Children.Add("CN=" + this.CommonName, CommonPropertyNames.ObjectClassNames.UserObjectClassName))
{
Utility.SetProperty(newUser, UserPropertyNames.Name, this.CommonName);
Utility.SetProperty(newUser, "userPassword", "Cambia$123");
FillUserProperties(newUser);
newUser.CommitChanges();
注意:
newUser.CommitChanges()
会抛出错误。
现在,如果我尝试使用 System.DirectoryServices.AccountManagement 是working
。一切都没有错误。
string OuDnDES = "OU=Portal,OU=NSI DESARROLLO,DC=company,DC=net";
using (var pc = new System.DirectoryServices.AccountManagement.PrincipalContext(System.DirectoryServices.AccountManagement.ContextType.Domain,
"mydomain.net",OuDnDES, "mydomain\\DES_GestorDirectorio", "1234"))
{
using (var up = new System.DirectoryServices.AccountManagement.UserPrincipal(pc))
{
up.SamAccountName = "testAD001";
up.EmailAddress = "test@realexx.es";
up.SetPassword("Change$123");
up.Enabled = true;
up.ExpirePasswordNow();
up.Save();
}
}
我不能使用 System.DirectoryServices.AccountManagement ,这是我之前的NET 3.5版本。
有什么建议吗?
答案 0 :(得分:1)
错误通常意味着未设置正在创建的对象的某些必需属性。尝试设置sAMAccountName属性
SearchResult ret = searcher.FindOneReturningDirectorySearchResult();
if (ret == null)
throw new ObjectNotFoundException("group", searcher.GetFilter());
using (DirectoryEntry parent = ret.GetDirectoryEntry())
{
parent.RefreshCache();
using (DirectoryEntry newUser = parent.Children.Add("CN=" + this.CommonName, CommonPropertyNames.ObjectClassNames.UserObjectClassName))
{
Utility.SetProperty(newUser, UserPropertyNames.Name, this.CommonName);
Utility.SetProperty(newUser, "userPassword", "Cambia$123");
Utility.SetProperty(newUser, "sAMAccountName", "testAD001");
FillUserProperties(newUser);
newUser.CommitChanges();