0

我想将一个计算机对象移动到另一个 OU 我连接到另一个域并且我总是得到一个 ComException 类型的异常"A referral was returned from the server"并且对象永远不会移动!

        try
        {
            //I get the exception here
            computerObject.MoveTo(new DirectoryEntry("LDAP://OU=someOU,OU=parentOU,DC=test,DC=com"));
            computerObject.CommitChanges();
        }
        catch (InvalidOperationException inOp)
        {
            //log 
        }
        catch (COMException comEx)
        {
            //log 
        }

        //joinPath.Close();
        finally
        {
            computerObject.Close();
        }

为了进行故障排除,我稍微更改了代码,但它再次不起作用。

computerObject.MoveTo(new DirectoryEntry("LDAP://OU=someOU,OU=parentOU,DC=test,DC=com"),
                      "admin@test.com","somepassowrd",AuthenticationTypes.Secure));

新异常的类型为 ComException"Logon failure: unknown user name or bad password." 我检查了活动目录中是否存在 OU 并且我有足够的权限。

我在这里关注了 Microsoft 文档https://msdn.microsoft.com/en-us/library/ms180856(v=vs.90).aspx 和许多 stackoverflow 问题。

更新:我在一个域中运行我的应用程序并在另一个域中进行更改,这可能是问题的原因

4

2 回答 2

0

我在同一个域中发布了我的代码,它工作得很好

于 2015-09-08T14:06:54.420 回答
0

您在此方法中有一个额外的括号:

computerObject.MoveTo(new DirectoryEntry("LDAP://OU=someOU,OU=parentOU,DC=test,DC=com"),"admin@test.com","somepassowrd",AuthenticationTypes.Secure));

它应该是

computerObject.MoveTo(new DirectoryEntry("LDAP://OU=someOU,OU=parentOU,DC=test,DC=com","admin@test.com", "somepassowrd", AuthenticationTypes.Secure));

这肯定会解释异常,我很惊讶你的调试器没有捕捉到它,除非你是徒手写的,或者你把它输入到你的问题中?

于 2015-10-01T17:20:13.447 回答