代码改变世界

DirectoryEntry类使用注意事项

2008-08-07 11:03  迭_戈  阅读(1059)  评论(0编辑  收藏  举报
如果开发的电脑没有加入域,而拥有某个域的帐号。现在要取得这个域的相关信息。

using System.DirectoryServices;
 
 string path = "LDAP://dc/dc=soft,dc=com";
  DirectoryEntry user = new DirectoryEntry(path, "userName", "password");

如果不事先通过windows登陆到域服务器.那么就得在web.config模拟帐号.不然会实例化抛出异常(没有权限)
<identity userName="soft\Administrator" password="password" impersonate="true" />

所以最好通过网上邻居访问一下域服务器。这样貌似就可以通过了域服务器的信任。然后在代码就可以成功连接了。如果电脑加入域里面。就不需要这步了。