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. More ActiveDirectory --- Binding as a DN?

More ActiveDirectory --- Binding as a DN?

Scheduled Pinned Locked Moved C#
questionwpfwcfsysadminwindows-admin
1 Posts 1 Posters 0 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

    Hey all, I'm working on an Active Directory web application. I've gotten further than my prior post - if you read my prior post, basically, the problem is this - I have to bind to the LDAP directory as a specific DN to authenticate (the username/password route for AD is not good enough since we are dealing with a non-MS ldap server). The process is this: * bind as an anonymous user * search with a filter of your own devising * obtain a single directoryentry object * bind to this directoryentry with the provided password This seemed like an easy thing to do initially - after all, we do have System.DirectoryServices --- the actual process was a little more involved. I've done the first three and got them working now (see below for the code). I'm now at step 4 - how do I bind to the directory using an existing DirectoryEntry and a password? My first thought was: DirectoryEntry bound = new DirectoryEntry(me.Path, "", password, AuthenticationTypes.ServerBind); ... but that does not seem to work (i.e. it always returns) - how can I tell if the binding was successful? Code to get to this point: // // Create the base path for the authentication. // string path = _host + "/" + _basedn; DirectoryEntry entry = new DirectoryEntry(path); // // Construct the filter necessary to search the // specified LDAP directory structure // Regex r = new Regex(Regex.Escape("$(login)")); string filter = r.Replace(_filter, username); // // Search for our user // DirectorySearcher dsrch = new DirectorySearcher(entry); dsrch.Filter = filter; dsrch.SizeLimit = 2; SearchResultCollection results = dsrch.FindAll(); // // Check to see if we found the user // if (results.Count == 0) return false; if (results.Count > 1) throw new Exception("Invalid user ID in LDAP Directory"); // // Convert the result into a DirectoryEntry // DirectoryEntry me = results[0].GetDirectoryEntry(); -Adrian

    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