C# 不愿意的服务器:Can';t在代码中解锁广告帐户
当我尝试使用自己的C#程序解锁一个广告帐户时,会出现以下错误: System.DirectoryServices.DirectoryServicesCOMException(0x80072035):服务器不愿意处理该请求 这是我用来解锁帐户的代码:C# 不愿意的服务器:Can';t在代码中解锁广告帐户,c#,active-directory,ldap,directoryservices,C#,Active Directory,Ldap,Directoryservices,当我尝试使用自己的C#程序解锁一个广告帐户时,会出现以下错误: System.DirectoryServices.DirectoryServicesCOMException(0x80072035):服务器不愿意处理该请求 这是我用来解锁帐户的代码: // "ldap" is an instance of my own class for accessing an LDAP server using (DirectoryEntry entry = ldap.GetEntry(objectGuid
// "ldap" is an instance of my own class for accessing an LDAP server
using (DirectoryEntry entry = ldap.GetEntry(objectGuid))
{
entry.InvokeSet("lockouttime", 0);
// I also tried:
entry.Properties["lockouttime"].Clear();
entry.CommitChanges();
}
我在多个域中使用这个软件,但只在其中一个域中出现这个错误,我不知道有什么区别。当我使用dsa.msc
解锁帐户时,一切正常
错误也会发生在不同的用户对象上,但这两个版本(Clear
和InvokeSet
)都适用于其他环境。谁能给我一个提示吗
注意:我使用域管理员凭据访问LDAP服务器。尝试:
我使用
System.DirectoryServices.AccountManagement
中的类成功地解决了这个问题:
using (var ctx = new PrincipalContext(
ContextType.Domain,
host,
rootDn,
ContextOptions.ServerBind | ContextOptions.Negotiate | ContextOptions.SecureSocketLayer,
username,
password))
using (var user = UserPrincipal.FindByIdentity(ctx, IdentityType.Guid, objectGuid.ToString()))
{
if (user != null)
{
user.UnlockAccount();
}
else
{
// user not found
}
}
但是我仍然不知道UnlockAccount
方法除了将lockOutTime
设置为零(或清除它)之外还有什么作用。这几乎就是我的代码(因为InvokeSet
除了设置unterry.Properties[“lockOutTime”].Value=0
)因此,这段代码不起作用——至少在上述环境中是这样。
using (var ctx = new PrincipalContext(
ContextType.Domain,
host,
rootDn,
ContextOptions.ServerBind | ContextOptions.Negotiate | ContextOptions.SecureSocketLayer,
username,
password))
using (var user = UserPrincipal.FindByIdentity(ctx, IdentityType.Guid, objectGuid.ToString()))
{
if (user != null)
{
user.UnlockAccount();
}
else
{
// user not found
}
}