मैंने एक ऐसी विधि लागू की जो सक्रिय निर्देशिका उपयोगकर्ताओं की एक सूची लौटाता है, मैं इस Domain\Administrator
जैसे SAMAccountName को पुनर्प्राप्त करना चाहता हूं।सक्रिय निर्देशिका से SAMAccountName को पुनर्प्राप्त कैसे करें
public Collection<software_user> GetUsersFromAD(String adConnectionString)
{
var users = new Collection<software_user>();
using (var directoryEntry = new DirectoryEntry(adConnectionString))
{
var directorySearcher = new DirectorySearcher(directoryEntry);
directorySearcher.Filter = "(&(objectClass=user))";
var propertiesToLoad = new[]
{
"SAMAccountName",
"displayName",
"givenName",
"sn",
"mail",
"userAccountControl",
"objectSid"
};
directorySearcher.PropertiesToLoad.AddRange(propertiesToLoad);
foreach (SearchResult searchEntry in directorySearcher.FindAll())
{
var userEntry = searchEntry.GetDirectoryEntry();
var ldapUser = new software_user();
ldapUser.User_name = NullHandler.GetString(userEntry.Properties["displayName"].Value);
if (string.IsNullOrEmpty(ldapUser.User_name))
continue;
ldapUser.User_name = NullHandler.GetString(userEntry.Properties["SAMAccountName"].Value);
ldapUser.email = NullHandler.GetString(userEntry.Properties["mail"].Value);
ldapUser.user_shortname = NullHandler.GetString(userEntry.Properties["givenName"].Value);
var userAccountControl = (int)userEntry.Properties["userAccountControl"].Value;
//ldapUser.IsActive = (userAccountControl & UF_ACCOUNTDISABLE) != UF_ACCOUNTDISABLE;
var sid = new SecurityIdentifier((byte[])userEntry.Properties["objectSid"][0], 0).Value;
//ldapUser.SId = sid;
users.Add(ldapUser);
}
}
return users;
}
मुझे "कुछ या सभी पहचान संदर्भों का अनुवाद नहीं किया जा सका।" अनुवाद में त्रुटि। – Shesha
मल्टी-डोमेन वन? आपको यह सुनिश्चित करना चाहिए कि आपका विज्ञापन कनेक्शन आपके वन जीसी के लिए है। यह भी हो सकता है कि आपकी इकाई वास्तव में एक अनाथ है। –