我参照了这个,我要做的是把域里的NT账号拉出来,和本机做对比。
http://www.cnblogs.com/KingOfSoft/archive/2007/05/12/743693.html
获取域账号主要写了3个方法,但是取出来的是null
protected void Page_Load(object sender, EventArgs e) { string[] NTUserList = GetOrganizationalUnit("LDAP://MyNT", "Administrator", "", "user"); } private string[] GetOrganizationalUnit(string domainADsPath, string username, string password, string schemaClassNameToSearch) { SearchResultCollection results = _ADHelper(domainADsPath, username, password, schemaClassNameToSearch); string[] sRe = GetGetOrganizationalUnitResults(results); results.Dispose(); return sRe; } private static SearchResultCollection _ADHelper(string domainADsPath, string username, string password, string schemaClassNameToSearch) { DirectorySearcher searcher = new DirectorySearcher(); searcher.SearchRoot = new DirectoryEntry(domainADsPath,username, password); searcher.Filter = "(objectClass=" + schemaClassNameToSearch + ")"; searcher.SearchScope = SearchScope.Subtree; searcher.Sort = new SortOption("name", System.DirectoryServices.SortDirection.Ascending); searcher.PageSize = 512; searcher.PropertiesToLoad.AddRange(new string[] { "name", "Path", "displayname", "samaccountname", "mail" }); SearchResultCollection results = searcher.FindAll(); return results; } private string[] GetGetOrganizationalUnitResults(SearchResultCollection results) { string sRe = string.Empty; if (results.Count == 0) throw new Exception("域中没有任何组织结构"); else { foreach (SearchResult result in results) { if (result.Path.IndexOf("OU=用户") < 0) continue; ResultPropertyCollection propColl = result.Properties; sRe += propColl["name"][0].ToString() + ','; } } if (sRe.Length > 0) sRe = sRe.Substring(0, sRe.Length - 1); return sRe.Split(','); }
还有就是_ADHelper()方法里的password参数是指的哪个password?windows的?
System.Security.Principal.WindowsIdentity.GetCurrent().Name;不行吗?
你要在iis设置中选中“集成windows 身份验证”