none
大神们,请进啊,C# AD域 删除域组织单位,报 “目录服务只可以在一个页状对象上运行”

    问题

  • DirectoryEntry domian = null;
    IsConnected("dachkj.com", "liubq", "abcd1234!", out domian);
    if (domian != null)
    {

    DirectorySearcher deSearch = new DirectorySearcher();
    deSearch.SearchRoot = domian;
    deSearch.Filter = "(&(objectClass=organizationalUnit)(OU=技术部))";
    SearchResultCollection results = deSearch.FindAll();
    if (results.Count > 0)
    {
    DirectoryEntry parentOuEntry = results[0].GetDirectoryEntry();


    DirectoryEntries dentrys = parentOuEntry.Children;
    DirectoryEntry organizeEntry = dentrys.Find("OU=技术小组", "organizationalUnit");
    dentrys.Remove(organizeEntry);
    organizeEntry.CommitChanges();

    //ouEntry.UsePropertyCache = true;
    //ouEntry.Rename("OU=技术小组1");
    //DirectoryEntry OU = ouEntry.Children.Add("OU=技术小组", "organizationalUnit");
    //OU.CommitChanges();
    //ouEntry.CommitChanges();
    }
    }

    在执行Remove抛异常,里面所用到的对象都能正常获取,很奇怪,求大神指点迷津!

    2016年12月14日 3:31

全部回复

  • Hi 安码,

    你能告诉我,程序抛出的是什么异常吗?根据代码,看不出什么问题。

    如果方便,你能提供一个能重新问题的demo吗?这样最容易解决问题。

    Best Regards,

    Hart


    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2016年12月15日 7:35
    版主