Пример #1
0
        public static string GetEmailByUsername(string username, string domain)
        {
            DirectoryEntry searchRoot   = new DirectoryEntry("LDAP://" + domain);
            SearchResult   searchResult = new DirectorySearcher(searchRoot)
            {
                Filter = "(&(objectClass=user)(displayName=" + username + "))"
            }.FindOne();
            DirectoryEntry directoryEntry = searchResult.GetDirectoryEntry();

            return(directoryEntry.Properties["mail"].Value.ToString());
        }
Пример #2
0
        public static string getAccount(string domain)
        {
            string         name         = new System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent()).Identity.Name;
            string         str          = name.Substring(name.IndexOf('\\') + 1);
            DirectoryEntry searchRoot   = new DirectoryEntry("LDAP://" + domain);
            SearchResult   searchResult = new DirectorySearcher(searchRoot)
            {
                Filter = "(&(objectClass=user)(sAMAccountName=" + str + "))"
            }.FindOne();
            DirectoryEntry directoryEntry = searchResult.GetDirectoryEntry();

            return(directoryEntry.Properties["sAMAccountName"].Value.ToString());
        }
Пример #3
0
        public static string GetUserIdByUsername(string username)
        {
            DirectoryEntry directoryEntry = null;

            foreach (string domain in domainList)
            {
                DirectoryEntry searchRoot   = new DirectoryEntry("LDAP://" + domain);
                SearchResult   searchResult = new DirectorySearcher(searchRoot)
                {
                    Filter = "(&(objectClass=user)(displayName=" + username + "))"
                }.FindOne();
                if (searchResult != null)
                {
                    directoryEntry = searchResult.GetDirectoryEntry();
                }
            }
            return(directoryEntry.Properties["sAMAccountName"].Value.ToString());
        }
Пример #4
0
        public static string GetUserId()
        {
            string username = new System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent()).Identity.Name;
            string str      = username.Substring(username.IndexOf('\\') + 1);

            string domain = "";

            if (username.StartsWith("KMHK"))
            {
                domain = "kmhk.local";
            }
            else if (username.StartsWith("KMAS"))
            {
                domain = "kmas.local";
            }
            DirectoryEntry searchRoot   = new DirectoryEntry("LDAP://" + domain);
            SearchResult   searchResult = new DirectorySearcher(searchRoot)
            {
                Filter = "(&(objectClass=user)(sAMAccountName=" + str + "))"
            }.FindOne();
            DirectoryEntry directoryEntry = searchResult.GetDirectoryEntry();

            return(directoryEntry.Properties["sAMAccountName"].Value.ToString());
        }