Quick way to retrieve user information Active Directory(检索用户信息的快速方法 Active Directory)
                            本文介绍了检索用户信息的快速方法 Active Directory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
                        
                        问题描述
如何从 Active Directory 查询用户信息?我有有效的代码,但它真的很慢.我正在使用 C#.这是我目前使用的代码:
How to query user information from Active Directory? I have code that works, but it's really slow. I'm using C#. This is the code I currently use:
    static void Main(string[] args)
    {
        SearchResultCollection sResults = null;
        try
        {
            //modify this line to include your domain name
            string path = "LDAP://EXTECH";
            //init a directory entry
            DirectoryEntry dEntry = new DirectoryEntry(path);
            //init a directory searcher
            DirectorySearcher dSearcher = new DirectorySearcher(dEntry);
            //This line applies a filter to the search specifying a username to search for
            //modify this line to specify a user name. if you want to search for all
            //users who start with k - set SearchString to "k"
            dSearcher.Filter = "(&(objectClass=user))";
            //perform search on active directory
            sResults = dSearcher.FindAll();
            //loop through results of search
            foreach (SearchResult searchResult in sResults)
            {
                if (searchResult.Properties["CN"][0].ToString() == "Adit")
                {
                    ////loop through the ad properties
                    //foreach (string propertyKey in
                    //searchResult.Properties["st"])
                    //{
                        //pull the collection of objects with this key name
                        ResultPropertyValueCollection valueCollection =
                        searchResult.Properties["manager"];
                        foreach (Object propertyValue in valueCollection)
                        {
                            //loop through the values that have a specific name
                            //an example of a property that would have multiple
                            //collections for the same name would be memberof
                            //Console.WriteLine("Property Name: " + valueCollection..ToString());
                            Console.WriteLine("Property Value: " + (string)propertyValue.ToString());
                            //["sAMAccountName"][0].ToString();
                        }
                    /
				 沃梦达教程
				
			本文标题为:检索用户信息的快速方法 Active Directory
				
        
 
            
        基础教程推荐
             猜你喜欢
        
	     - JSON.NET 中基于属性的类型解析 2022-01-01
 - 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
 - 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
 - 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
 - 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
 - 全局 ASAX - 获取服务器名称 2022-01-01
 - 首先创建代码,多对多,关联表中的附加字段 2022-01-01
 - 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
 - 如何动态获取文本框中datagridview列的总和 2022-01-01
 - 错误“此流不支持搜索操作"在 C# 中 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
						
						
						
						
						
				
				
				
				