我们在使用活动目录和移动/重命名 OU 时遇到问题。这仅在我们在两个域控制器之间进行复制时发生。我们得到的例外是:
System.ServiceModel.FaultException:服务器上没有这样的对象。(来自 HRESULT 的异常:0x80072030)
当我们尝试在活动目录中移动和重命名 OU 时,我们会收到此错误消息的变体。这是有问题的代码:
PrincipalContext context = GetPrincipalContext();
using (UserPrincipal principal = UserPrincipal.FindByIdentity(context, IdentityType.Guid, id.ToString()))
{
if (principal == null)
{
throw new InvalidOperationException();
}
string oldEmail = principal.EmailAddress;
principal.EmailAddress = newEmail;
principal.Save();
DirectoryEntry entry = principal.GetUnderlyingObject() as DirectoryEntry;
DirectoryEntry targetDirectoryEntry = null;
string target = null;
// Access the underlying DirectoryEntry to rename it:
try
{
if (entry == null)
{
throw new InvalidOperationException();
}
entry.RefreshCache();
entry.Rename(string.Format("CN={0}", newEmail));
// Move the DirectoryEntry to the correct location.
target = BuildOrganizationalUnitName(newEmail);
targetDirectoryEntry = FindDirectoryEntry(target);
if (targetDirectoryEntry == null)
{
throw new InvalidOperationException();
}
entry.MoveTo(targetDirectoryEntry);
entry.CommitChanges();
}
catch (Exception e)
{
// do some logging
}
finally
{
if (entry != null)
{
entry.Dispose();
}
if (targetDirectoryEntry != null)
{
targetDirectoryEntry.Dispose();
}
}
}
所以我有两个问题:
- 上面试图移动和重命名 OU 的代码有什么问题吗?
- 如果没有,有什么方法可以确保两个 DC 在移动/重命名后保持同步?