Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. ActiveDirectory / LDAP Searching

ActiveDirectory / LDAP Searching

Scheduled Pinned Locked Moved C#
sysadminalgorithmsdata-structureshelpquestion
2 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Adrian Hall
    wrote on last edited by
    #1

    I have a requirement to authenticate users against a non-MS LDAP service using non-standard attributes. The general method of doing this is to search for the user anonymously, then re-bind to the server with the found DN and the provided password. I'm using the following code to implement the search, but it always fails (error provided below): DirectoryEntry me; string filter = "(mailLocalAddress=" + uid + ")"; string path = "ldap://10.10.240.19/o=Top"; DirectoryEntry dbE = new DirectoryEntry(path); DirectorySearcher dsE = new DirectorySearcher(dbE, filter); dsE.SizeLimit = 2; SearchResultCollection src = dsE.FindAll(); if (src.Count == 0) { throw new AuthenticationException("Login Incorrect"); } if (src.Count > 1) { throw new AuthenticationException("Invalid LDAP Response"); } me = src[0].GetDirectoryEntry(); The error I get is: System.Runtime.InteropServices.COMException (0x80040E37): Unknown error (0x80040e37) 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() at Portal.Login.CheckPassword(String uid, String pass) in c:\inetpub\wwwroot\portal\login.aspx.cs:line 108 Now, my base DN is indeed "top". What I am expecting is that the program binds anonymously to the specified LDAP server and does a sub-tree search on o=Top for my filter. Anyone have any ideas? -Adrian

    A 1 Reply Last reply
    0
    • A Adrian Hall

      I have a requirement to authenticate users against a non-MS LDAP service using non-standard attributes. The general method of doing this is to search for the user anonymously, then re-bind to the server with the found DN and the provided password. I'm using the following code to implement the search, but it always fails (error provided below): DirectoryEntry me; string filter = "(mailLocalAddress=" + uid + ")"; string path = "ldap://10.10.240.19/o=Top"; DirectoryEntry dbE = new DirectoryEntry(path); DirectorySearcher dsE = new DirectorySearcher(dbE, filter); dsE.SizeLimit = 2; SearchResultCollection src = dsE.FindAll(); if (src.Count == 0) { throw new AuthenticationException("Login Incorrect"); } if (src.Count > 1) { throw new AuthenticationException("Invalid LDAP Response"); } me = src[0].GetDirectoryEntry(); The error I get is: System.Runtime.InteropServices.COMException (0x80040E37): Unknown error (0x80040e37) 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() at Portal.Login.CheckPassword(String uid, String pass) in c:\inetpub\wwwroot\portal\login.aspx.cs:line 108 Now, my base DN is indeed "top". What I am expecting is that the program binds anonymously to the specified LDAP server and does a sub-tree search on o=Top for my filter. Anyone have any ideas? -Adrian

      A Offline
      A Offline
      Adrian Hall
      wrote on last edited by
      #2

      After much searching, I found there is a difference between ldap:// and LDAP:// --- go figure.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups