Searching multiple domains ...

Last post 07-26-2007 10:56 AM by dsouzvi. 6 replies.

Sort Posts:

  • Sleep [|-)] Searching multiple domains ...

    06-01-2007, 11:22 AM
    • Loading...
    • dsouzvi
    • Joined on 05-16-2007, 8:49 PM
    • Posts 11

    Hey All,

     I have successfully coded to get the information from our AD Domain but because of the mergers we have many trusted domains and the users needs to be verified against them as well.  But I really don't know how its been done in C#.  I know it can be done because the Sharepoint 2003 finds any user across the company without making any changes.  So, I assume there is a easy way to do the search in trusted domains when the user is not found on the local/default domain.

     Any one has any sample code to do that please?

     My current code is as follows:

    public void GetUserInfo(String sDomainUserID)
          {
          String sUserID = GetUserID(sDomainUserID);
          String sFilter = "(&(sAMAccountname=" + sUserID + ")(objectClass=user))";

          string sDomain = "LDAP://" + WebConfigurationManager.AppSettings["domain"];

          DirectoryEntry DirEntry = new DirectoryEntry(sDomain.Trim());
          DirEntry.AuthenticationType = AuthenticationTypes.Secure;

          DirectorySearcher DirSearcher = new DirectorySearcher(DirEntry);
          DirSearcher.Filter = sFilter;

          SearchResult Result = DirSearcher.FindOne();

          DirectoryEntry GetDirEntry = Result.GetDirectoryEntry();

          foreach (string propertyName in Result.Properties.PropertyNames)
            {
            foreach (object sItem in Result.Properties[propertyName])
              {
                switch (propertyName)
                {
                case "name":
                  string[] UserName = ((string)sItem).Split(new Char[] { ',' });
                  sFName = UserName[1].Trim();
                  sLName = UserName[0].Trim();
                  break;
                case "streetaddress":
                  sAddress = GetPropertyValue(sItem).Replace("\r\n", " ");
                  break;
                case "l":
                  sCity = GetPropertyValue(sItem);
                  break;
                case "postalcode":
                  sZip = GetPropertyValue(sItem);
                  break;
                case "title":
                  sTitle = GetPropertyValue(sItem);
                  break;
                case "company":
                  sCompany = GetPropertyValue(sItem);
                  break;
                case "extensionattribute2":
                  sRCCode = GetPropertyValue(sItem);
                  break;
                case "extensionattribute1":
                  sUID = GetPropertyValue(sItem);
                  break;
                case "mail":
                  sEMail = GetPropertyValue(sItem);
                  break;
                case "info":
                  sIPager = GetPropertyValue(sItem).Replace("ipager: ", "");
                  break;
                case "extensionattribute11":
                  if (GetPropertyValue(sItem) == "BlackBerryUser")
                  { boolBBUser = true; }
                  else
                  { boolBBUser = false; }
                  break;
                case "extensionattribute5":
                  sEmpType = GetPropertyValue(sItem);
                  break;
                case "department":
                  sDept = GetPropertyValue(sItem);
                  break;
                case "telephonenumber":
                  sPhone = GetPropertyValue(sItem);
                  break;
                case "st":
                  sState = GetPropertyValue(sItem);
                  break;
                case "extensionattribute13":
                  sATTUID = GetPropertyValue(sItem);
                  break;
                case "extensionattribute3":
                  sGLC = GetPropertyValue(sItem);
                  break;
                case "extensionattribute4":
                  sCUID = GetPropertyValue(sItem);
                  break;
                case "manager":
                  DirectoryEntry de = new DirectoryEntry("LDAP://" + sItem.ToString());
                  sSupUID = GetPropertyValue(de.Properties["samaccountname"].Value);
                  sSupEMail = GetPropertyValue(de.Properties["mail"].Value);
                  sSupiPager = GetPropertyValue(de.Properties["info"].Value).Replace("ipager: ", "");
                  sSupPhone = GetPropertyValue(de.Properties["telephonenumber"].Value);
                  break;
                }
              }
            }
          }

     I would greatly appreciate if anyone could help me out in this matter.

     thanks,

    vincent

  • Re: Searching multiple domains ...

    07-12-2007, 5:33 AM
    • Loading...
    • manach
    • Joined on 05-11-2005, 5:03 PM
    • Ho Chi Minh City, Vietnam
    • Posts 12

    Hi Vincent,

    I'm facing with this problem too.

    Have you solved it yet?

    If you have, could you share it?

    Thanks,

    Manach

  • Re: Searching multiple domains ...

    07-12-2007, 6:43 AM
    • Loading...
    • dsouzvi
    • Joined on 05-16-2007, 8:49 PM
    • Posts 11

    Manach,

     I do not know what i did is the right way or not but I could not get any help so i did it.  What i did was, I put all the domain names that i know of in the appsettings key in the web config and started looping through the array of domain until the user is found. 

     this kind of works but I am pretty sure there should be a better way to do this.

     Hope, this helps,

     -vincent

  • Re: Searching multiple domains ...

    07-18-2007, 3:08 AM
    • Loading...
    • manach
    • Joined on 05-11-2005, 5:03 PM
    • Ho Chi Minh City, Vietnam
    • Posts 12

    Hi Vincent,

    Thanks for your reply.

    Your solution is used to be my way but it seem to be hard-coded (I stored all domains i known on a configuration file, the same as you store it on web config).

    After doing some investigation, i found that if a domain have domains trust it, there will have a related username with that domains.

    For example:

    I have a domain named "mycompany.com". This domain have a trusted domain named "yourcompany.com". So if i query all users on "mycompany.com", i also get a special user name "YOURCOMPANY$" (an all capital name with a dollar sign at the end). This user indicate that "mycompany.com" domain has a trusted relationship with a domain name "yourcompany". And a new problem occurs that we still cannot know the remaining of that name. ie, we cannot know it has relationship with "yourcompany.com or .net or something else".

    May this helps you to do more researches.

    By the way, you can reach me at namchuong@hotmail.com

    Thanks,

    Manach.

     

  • Re: Searching multiple domains ...

    07-18-2007, 7:05 AM
    • Loading...
    • dsouzvi
    • Joined on 05-16-2007, 8:49 PM
    • Posts 11

    Thanks manach for letting me know. Big Smile

     I greatly appreciate if you could post here if you find any further information on this issue.  Since I am very busy with other things right now I have given up with my research on this.  Once the things get smother then will do some more research.  As I said before there should be a way to get the userinformation as long as you know one of the domains in the trust.  But finding out is a mistery.Zip it!

  • Re: Searching multiple domains ...

    07-19-2007, 12:53 AM
    Answer
    • Loading...
    • manach
    • Joined on 05-11-2005, 5:03 PM
    • Ho Chi Minh City, Vietnam
    • Posts 12

    Hi all,

    I found the way to do that now.

    You can refer to this link to get the source code.

    http://forums.asp.net/p/1015799/1811544.aspx#1811544

    Thanks,

    Manach.

  • Re: Searching multiple domains ...

    07-26-2007, 10:56 AM
    • Loading...
    • dsouzvi
    • Joined on 05-16-2007, 8:49 PM
    • Posts 11

    Thanks Manach.  I haven't tried this yet but will try and let you know how it goes.

     -vincent

Page 1 of 1 (7 items)
Microsoft Communities
Page view counter