深入探索Active Directory与ASP.NET开发
1. 操作Active Directory
在处理Active Directory时,我们可以借助 System.DirectoryServices
命名空间中的类来轻松访问其服务。以下是一段示例代码,展示了如何获取特定对象的属性:
de.Path = "LDAP://" + hostname + "CN=" + objectType + "," + schemaNamingContext;
DS.PropertyCollection properties = de.Properties;
DS.PropertyValueCollection values = properties["systemMayContain"];
data = new String[values.Count];
values.CopyTo(data, 0);
return data;
这里需要注意的是,由于在Windows Forms应用程序中, System.DirectoryServices
命名空间的 PropertyCollection
类与 System.Data.PropertyCollection
存在命名冲突,为避免使用冗长的名称,我们可以对命名空间进行缩写:
using DS = System.DirectoryServices;
<