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");
}
}
summary.Append("\r\n");
}
Console.WriteLine(summary);
}
}
the exception I get is:
System.DirectoryServices.DirectoryServicesCOMException was unhandled
Message=An invalid dn syntax has been specified.
Source=System.DirectoryServices
ErrorCode=-2147016654
ExtendedError=13
ExtendedErrorMessage=Invalid DN
StackTrace:
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_AdsObject()
at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
at System.DirectoryServices.DirectorySearcher.FindAll()
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.
Thank you
Lepide Softwares Pvt. Ltd.
http://www.lepide.com/
products:
Lepide Exchange Manager,
Lepide Active Directory Self Service,
Lepide Active Directory Management and reporting,
Mail id: anilk@lepide.com
contact no: 1-800-814-0578
amirtofighi
0 Points
2 Posts
How to connect and authenticate users with LDAP
May 02, 2012 07:30 PM|LINK
Hi,
I am able to connect to the ldap and get the user info even without a password by just putting this in my browser:
ldap://directory.abc.edu/uid=myUserID,ou=People,o=abc.edu
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");
}
}
summary.Append("\r\n");
}
Console.WriteLine(summary);
}
}
the exception I get is:
System.DirectoryServices.DirectoryServicesCOMException was unhandled
Message=An invalid dn syntax has been specified.
Source=System.DirectoryServices
ErrorCode=-2147016654
ExtendedError=13
ExtendedErrorMessage=Invalid DN
StackTrace:
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_AdsObject()
at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
at System.DirectoryServices.DirectorySearcher.FindAll()
voodooclanbo...
Member
28 Points
4 Posts
Re: How to connect and authenticate users with LDAP
May 04, 2012 10:49 AM|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.
Thank you
http://www.lepide.com/
products:
Lepide Exchange Manager,
Lepide Active Directory Self Service,
Lepide Active Directory Management and reporting,
Mail id: anilk@lepide.com
contact no: 1-800-814-0578
amirtofighi
0 Points
2 Posts
Re: How to connect and authenticate users with LDAP
May 04, 2012 01:11 PM|LINK
Hi,
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,
gww
Contributor
2143 Points
458 Posts
Re: How to connect and authenticate users with LDAP
May 04, 2012 07:57 PM|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