Last post May 04, 2012 08:57 PM by gww
May 02, 2012 08:30 PM|amirtofighi|LINK
I am able to connect to the ldap and get the user info even without a password by just putting this in my browser:
I have used "abc" "myUserID" as just place holder for the actual words as I can't show them here.
I have a website that needs to authenticate users from this ldap and don't let them login otherwise. I have written the follwoing code just to test and when I run it I get a dn syntax error exception.
Can anyone please help me with this and tell me how should I set up the path and the parameters so that I can get a reply from the ldap server:
this is the code I wrote:
using (DirectoryEntry root = new DirectoryEntry())
root.Path = "LDAP://directory.abc.edu";
root.Username = "myDomain\myUserID"; (I even tried it without the domain as I don't use it in browser path but get the response!)
root.Password = "myPassword";
using (DirectorySearcher searcher = new DirectorySearcher())
searcher.SearchRoot = root;
SearchResultCollection results = searcher.FindAll(); -----> When I run it, on this line I get an exception (see below for exception)
StringBuilder summary = new StringBuilder();
foreach (SearchResult result in results)
foreach (string propName in result.Properties.PropertyNames)
foreach (string s in result.Properties[propName])
summary.Append(" " + propName + ": " + s + "\r\n");
the exception I get is:
System.DirectoryServices.DirectoryServicesCOMException was unhandled
Message=An invalid dn syntax has been specified.
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
May 04, 2012 11:49 AM|voodooclanboy|LINK
Once you have found the user's DN you should then add those credentials to the first context's environment and then try a reconnect(). That does the LDAP bind operation.
May 04, 2012 02:11 PM|amirtofighi|LINK
Thanks for your reply but it's very vague for me! What is the DN? Did I say that I have it? I can't even connect to it programmatically.
Please be more specific. I included my code and the URL I use in the browser for that matter.
Please kindly write some code for me. Thanks,
May 04, 2012 08:57 PM|gww|LINK
This is a good link for those working with C and ldap,
http://www.codeproject.com/Articles/18102/Howto-Almost-Everything-In-Active-Directory-via-C. That exception error indicates the path may be incorrect.
When searching ldap for accounts you do not want to have the domain with the user name. So user UserID no domain\UserID