Last post Apr 23, 2015 09:55 AM by AGodinho
Apr 22, 2015 11:16 AM|Aragorn2004|LINK
Hi, i've an application (IIS on Windows 2003 Server, ASP.NET 2.0) that validate
credentials users on a SQL Server 2008 where are defined also groups.
Now i've need to authenticate user and password on LDAP server. I made an authentication page.
The Machine where the authentication page runs is accreditate (on firewall) on machine where LDAP Server runs.
From LDAP Server Administrator i've received this parameters:
IP Address, O=y1,C=y2
I'm trying with something like this
Step1: Dim entry As DirectoryEntry = New DirectoryEntry(path, domainAndUsername, pwd, TypeAuthentic)
Step2: Dim obj As Object = entry.NativeObject
Where path= "LDAP://151.xxx.xxx.225/OU=y1,C=y2"
I've tried also "LDAP://151.xxx.xxx.225/DC=y1,DC=y2" and many more combinations.
I've tried all type of authentication.
I've passed username like domainname\username suppossing domainname=y1.y2 but also only username without domain
But i received always error (on Step2) that is
dn is not valid (when i use an authentication type different from Encrypted or SSL)
or Server is not operative (when i use an authentication type equal to Encrypted or SSL)
Any ideas ? Other parameters that in this moment i've not. ?
Thanks in advance for your precious time.
Apr 23, 2015 09:55 AM|AGodinho|LINK
I've done this do get a property from the LDAP server
public static string getLdapProperty(string property, string userLogin)
DirectoryEntry oroot = new DirectoryEntry(@"LDAP://mycompany.com:389/DC=mycompany,DC=pt", @"mycompany\ldapusr", "PASSWORD-HERE");
DirectorySearcher osearcher = new DirectorySearcher(oroot);
osearcher.Filter = "(&(cn=" + userLogin + ")(objectCategory=person))";
oresult = osearcher.FindAll();
if (oresult.Count == 0)
return "User not found";
foreach (SearchResult result in oresult)
if (result.GetDirectoryEntry().Properties[property].ToString() != string.Empty)
catch (Exception ex)
return "ERROR reading [" + property + "] from user [" + userLogin + "]";
return "no data found";
And call it like this (assuming you had a AGodinho valid user on the LDAP server):
public static string getName(string userLogin)
return getLdapProperty("displayName", userLogin);
public static void Main()
Console.WriteLine("Full name for user AGodinho is" + getName("AGodinho"));
just create methods to get the different properties you need or pass them as args.