我正在使用这种简单的方法在当前域中查找用户,对于所有“存在”的用户都有效,但我无法找到任何确定用户不存在的方法。
string userLDAP = @"MYDOMAIN/username";
string path = "WinNT://" + userLDAP ;
DirectoryEntry root = new DirectoryEntry(path, null, null, AuthenticationTypes.Secure);
除了让异常抛出之外,我如何使用目录条目来确定用户不存在呢?
if (root.Properties != null)
if (root.Properties["objectSid"] != null) //// EXCEPTION HERE
if (root.Properties["objectSid"][0] != null)