首页 新闻 会员 周边

BS应用程序如何AD认证?

0
悬赏园豆:120 [已解决问题] 解决于 2009-12-08 16:13

我参照了这个,我要做的是把域里的NT账号拉出来,和本机做对比。
http://www.cnblogs.com/KingOfSoft/archive/2007/05/12/743693.html
获取域账号主要写了3个方法,但是取出来的是null

C# code
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的?

问题补充: 已经解决 private static string GetUserFieldValueFromAD(string domainName, string loginName,string fieldName) { string adPath = "LDAP://" + domainName; DirectoryEntry de = new DirectoryEntry(adPath); de.AuthenticationType = AuthenticationTypes.None; DirectorySearcher deSearch = new DirectorySearcher(); deSearch.SearchRoot = de; //set the search filter deSearch.Filter = "(&(objectClass=user)(sAMAccountName=" + loginName + "))"; deSearch.SearchScope = SearchScope.Subtree; //find the first instance SearchResult results = deSearch.FindOne(); de = new DirectoryEntry(results.Path); if (de.Properties.Contains(fieldName)) return de.Properties[fieldName][0].ToString(); return ""; }
莫生的主页 莫生 | 初学一级 | 园豆:45
提问于:2009-12-03 18:12
< >
分享
最佳答案
0

System.Security.Principal.WindowsIdentity.GetCurrent().Name;不行吗?

收获园豆:60
woody.wu | 老鸟四级 |园豆:3621 | 2009-12-03 19:50
这个方法取出来的结果就是NT AUTHORITY/NETWORK SERVICE,不是具体的域名,在C/S架构下是正确的,但是在B/S架构下就有问题,我的语句是这样的: string name = System.Security.Principal.WindowsIdentity.GetCurrent().Name; name = Request.LogonUserIdentity.Name; 。。
莫生 | 园豆:45 (初学一级) | 2009-12-04 09:22
其他回答(1)
0

你要在iis设置中选中“集成windows 身份验证”

收获园豆:60
persialee | 园豆:3217 (老鸟四级) | 2009-12-04 15:10
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册