日期:2014-05-20 浏览次数:20864 次
public static DirectoryEntry GetDirectoryObject() //连接AD
{
DirectoryEntry entry = new DirectoryEntry("LDAP://gdepb.gov.cn", "", "", AuthenticationTypes.Secure);
return entry;
}
public string GetOU(string username)
{
string result = string.Empty;
PrincipalContext yourDomain = new PrincipalContext(ContextType.Domain);
UserPrincipal user = UserPrincipal.FindByIdentity(yourDomain, username);
if (user != null)
{
DirectoryEntry directoryEntry = (user.GetUnderlyingObject() as DirectoryEntry);
if (directoryEntry != null)