We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

User authentication LDAP C# 3.5

i9796674
i9796674 asked
on
Medium Priority
2,802 Views
Last Modified: 2013-12-19
Hello,

Could please anyway send a sample code to
1. authenticate a user
2. check if the user is part of a group
3. Show attributes for that user, like name, surname, etc

I have tried different pieces of code I found on Google but nothing seems to work ok.

Thanks
Alonso
Comment
Watch Question

CERTIFIED EXPERT
Commented:
Here is a link for many different AD methods.  
http://www.codeproject.com/KB/system/everythingInAD.aspx
Also the following example may help you out, just set the properties to be the name, surname etc.


SortedList idList = new SortedList();
            DirectorySearcher search = new DirectorySearcher(domain);
            search.Filter = "(SAMAccountName=" + userName + ")";
            search.SearchScope = SearchScope.Subtree;
            search.PropertiesToLoad.Add("memberOf");
            int listIndex = 0;
 
            SearchResultCollection result = search.FindAll();           
            foreach (SearchResult res in result)
            {
                foreach (ResultPropertyValueCollection arr in res.Properties.Values)
                {
                    foreach (object obj in arr)
                    {
                        idList.Add(listIndex, myString);
                    }
                }
            }

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Hi,

Thanks for the code but it does not seem to work.

I have changed the domain and userName but what should I do with myString? where is it defined?

I know the page you mention but I have not found an example that works well doing what I wanted to do. I thought to use LDAP on 3.5 it would be something link to the System.DirectoryServices.Protocols namespace... or am I wrong here?

Thanks
Alonso
CERTIFIED EXPERT

Commented:
Whoops!  Thats the problem with a fast copy/paste.  You can ignore the line  idList.Add(listIndex, myString); as that was just me building a specific string and passing it back in the list.  You can publish each object (in foreach (object obj in arr)) to whatever you want and it should give you the list of groups for a specific user.  
Commented:
http://www.skilldrive.com/book/DOTNETinSamples.htm

You have a whole list of samples here
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.