2012年7月11日 星期三
索取AD帳號的語法
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
public static string strLDAP = "LDAP://" + System.Configuration.ConfigurationManager.AppSettings["AD_HOST"] + "/OU=xxx,OU=xxx,dc=xxx,dc=xxx";
LogonName = UserPrincipal.Current.SamAccountName;
DirectoryEntry entry = null;
entry = new DirectoryEntry(strLDAP);
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.Filter = "(&(objectClass=User)(name=" + LogonName + "))";
searcher.PropertiesToLoad.AddRange(new string[] { "xx", "xxx", "xxxx", "xxxxx", "x" });
SearchResult result = searcher.FindOne();
ResultPropertyCollection propColl = result.Properties;
if (propColl["name"].Count > 0)
ViewData["name"] = propColl["name"][0].ToString();
if (propColl["department"].Count > 0)
ViewData["department"] = propColl["department"][0].ToString();
if (propColl["displayname"].Count > 0)
ViewData["displayname"] = propColl["displayname"][0].ToString();
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言