Avatar of SirReadAlot
SirReadAlot
 asked on

Querying Ldap ou folders with c#

Hi Experts,

I have this piece of code which querys one OU Folder and works. how do i query two OU folders to ensure that all users are accounted for?
----------------------------------
 string userDN = "CN=" + Username.Value + ", OU=IS, OU=TY  O=HCFHE"; // Change to match your Distinguished Name (DN)
-------------------------------------

Also why is it that just the parent [O=HCFHE] can not be queried?

thanks
protected void Login_Click(object sender, EventArgs e)
    {
       string userDN = "CN=" + Username.Value + ", OU=IS,  O=HCFHE"; // Change to match your Distinguished Name (DN)
       LdapConnection ldapConn = new LdapConnection();
        ldapConn.Connect("****", ***); 

        try
        {
            ldapConn.Bind(userDN, Password.Value);
            FormsAuthentication.RedirectFromLoginPage(Username.Value, PersistCookie.Checked);
        }
        catch (LdapException)
        {
            lblMsg.Text = "Incorrect username/password combination.";
        }
    }

Open in new window

DatabasesASP.NETC#

Avatar of undefined
Last Comment
Kumaraswamy R

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Kumaraswamy R

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SirReadAlot

ASKER
How do I query multiple OUS

  if ((userDN = "CN=" + Username.Value + ", OU=IS,  O=HCFHE") || (userDN = "CN=" + Username.Value + ", OU=EaST,  O=HCFHE"))
          {
              LdapConnection ldapConn = new LdapConnection();
              ldapConn.Connect("10.1.1.220", 389); // 389 is the default port.        

Error      1      Operator '||' cannot be applied to operands of type 'string' and 'string'      

thanks
SOLUTION
Kumaraswamy R

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23