我现在想要在一台机器上检索这台机器所在域中的一个User,但是使用如下方法在大多数的情况下是好使的:
string LDAPstring = "GC:";
DirectoryEntry de = new DirectoryEntry(LDAPstring);
IEnumerator enumerator = de.Children.GetEnumerator();enumerator.MoveNext();DirectoryEntry current = (DirectoryEntry)enumerator.Current;DirectorySearcher search = new DirectorySearcher(current);
...(实际检索过程略)可是最近却在一台域控中出现了这样的错误:“Enumerator is positioned before the first item or after the last item.”
我知道这句话是在MoveNext之后运行“DirectoryEntry current = (DirectoryEntry)enumerator.Current;”时抛出来的,但是不知道具体原因。
希望有高手能帮帮忙不论是针对这个错误有解决方案,还是给出另一种取得本地域的解决方案都会给分的。
取本地域的时候要考虑到这台机器不是域控制器的情况,谢谢。
string LDAPstring = "GC:";
DirectoryEntry de = new DirectoryEntry(LDAPstring);
IEnumerator enumerator = de.Children.GetEnumerator();enumerator.MoveNext();DirectoryEntry current = (DirectoryEntry)enumerator.Current;DirectorySearcher search = new DirectorySearcher(current);
...(实际检索过程略)可是最近却在一台域控中出现了这样的错误:“Enumerator is positioned before the first item or after the last item.”
我知道这句话是在MoveNext之后运行“DirectoryEntry current = (DirectoryEntry)enumerator.Current;”时抛出来的,但是不知道具体原因。
希望有高手能帮帮忙不论是针对这个错误有解决方案,还是给出另一种取得本地域的解决方案都会给分的。
取本地域的时候要考虑到这台机器不是域控制器的情况,谢谢。
解决方案 »
- C#多个线程访问一个队列问题,请大侠们帮帮忙
- c#中用oledbdataadapter.updata将datatable中的数据更新到dbf太慢,求解决方法!
- 开始出来了,后来错了,谁能帮我看看哪错了,谢谢!
- 使用Ext.ajax.request()查询数据库的值 然后赋值给表单的文本框???
- 进制转换的问题
- WPF有没有errprovicer
- C#写的类,添加了XML注释(///<summary> myremark ///</summary> ) ,为什么编译为dll后,这些函数参数注释却没有显示?
- 有没有好的可以跟踪程序内存使用和线程数的工具?
- WINCE6.0 键盘钩子 SetWindowsHookEx返回0,安装钩子失败,求解
- 请问:在客户端事件中,如何去触发服务器端的事件。
- 请教取文本内容的问题
- 我是才鸟!!高手帮帮我!!
{
TreeNode node = new TreeNode(text);
parant.Nodes.Add(node);
return node;
}
private void EnumChildren(DirectoryEntry entry,TreeNode entryNode)
{
if(entry.Children!=null)
{
foreach(DirectoryEntry i in entry.Children) {
EnumChildren(i,AddNode(entryNode,i.Name));
}
}
}
private void Enumerate(string path)
{
try
{
using(DirectoryEntry root = new DirectoryEntry(path))
{
TreeNode node = new TreeNode(root.Name);
treeView1.Nodes.Add(node);
EnumChildren(root,node);
}
}
catch {}
}
你这里的Enumerate(string path)函数的参数应该是LDAP路径吧?
我是想得到本机所在的域,如果我知道这个LDAP路径的话我就可以直接连接了,但是现在我并不知道呀。
我自己使用了另一种方法来尝试获得本机所在的域,就是使用Domain类里的GetCurrentDomain的方法,然后去获得这个Domain的DC的IP地址(前提是这台机器不是08的环境,否则可能会得到IPV6的地址)。最后组成LDAP路径然后重新构造DirectorySearcher对象进行检索。
但是我总认为还会有其他更好的办法,或者是对我所说的那个异常信息有更好的解释。