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. Directory Services

Directory Services

Scheduled Pinned Locked Moved C#
csharpasp-nettutorialquestionlearning
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.
  • J Offline
    J Offline
    Jacob D Dixon
    wrote on last edited by
    #1

    I am needing to get AD information from a user logon name like AEM\jdixon Im using this for a website to authenticate people to get their Division, First and Last name automatically without them having to sign in or anything. This is what I have:

    		using (DirectoryEntry root = new DirectoryEntry())
    		{
    			root.Username = username;
    			root.Password = password;
    			root.Path = LDAPPath;
    
    			using (DirectorySearcher searcher = new DirectorySearcher())
    			{
    				searcher.SearchRoot = root;
    				searcher.SearchScope = SearchScope.Subtree;
    				searcher.Filter = "(objectClass=user)";
    				searcher.PropertiesToLoad.Add("msDS-PrincipalName");
                                        seacher.PropertiesToLoad.Add("divison");
    
    				SearchResultCollection results = searcher.FindAll();
    				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");
    				}
    				textBoxResults.Text = summary.ToString();
    			}
    		}
    

    Now I got this from someone else on here that I seen in an article. But I also have my book here and I'm not seeing what I want to do. See in ASP.net you can get their Windows Logon name simple right? Which would pull (lets use mine for example) AEM\JDIXON So now that I have AEM\JDIXON, I want to search AD (first to make sure it exist) and if it exist I want it to pull what DIVISON and the First and Last name. This is for a ticket application.

    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