/// <summary> /// Initialize new instance of this active directory context. /// </summary> /// <param name="gcHostname">The Global Catelog Hostname a Domain Controller. /// If no hostname is provided, the current context is used. /// </param> public Context(string gcHostname = "") { if (string.IsNullOrEmpty(gcHostname)) { var context = new DirectoryContext(DirectoryContextType.Forest); this.gcHostname = GlobalCatalog.FindOne(context).Name; } else { this.gcHostname = gcHostname; } }
/// <summary> /// Initialize new instance of this active directory context. /// </summary> /// <param name="gcHostname">The Global Catalog Hostname a Domain Controller. /// If no hostname is provided, the current context is used. /// <param name="searchType">Whether the searches will be done as GC (default) or LDAP. /// Global Catalog will ensure that the results are searched for in the entire catalog (whether in the host /// or other domains in the forest) /// But, if the host controller happens to contains the search entities, LDAP can be faster.</param> /// </param> public Context(string gcHostname = "", SearchType searchType = SearchType.GlobalCatalog) { if (string.IsNullOrEmpty(gcHostname)) { var context = new DirectoryContext(DirectoryContextType.Forest); this.gcHostname = GlobalCatalog.FindOne(context).Name; } else { this.gcHostname = gcHostname; } searchProtocol = searchType == SearchType.GlobalCatalog ? "GC" : "LDAP"; }
public static void GetGlobalCatalogConfigData() { Console.WriteLine("<--GLOBAL CATALOG CONFIGURATION DATA-->\n"); // Get a forest context DirectoryContext forestContext = new DirectoryContext( DirectoryContextType.Forest); GlobalCatalog gc; try { // bind to a global catalog server in the forest gc = GlobalCatalog.FindOne(forestContext); Console.WriteLine("Finding one global catalog " + "in the current forest:"); Console.WriteLine("Name: {0}", gc); Console.WriteLine("Site: {0}", gc.SiteName); // list roles held by the GC Console.WriteLine("\nRoles:"); foreach (ActiveDirectoryRole role in gc.Roles) { Console.WriteLine("\t{0}", role); } // list partitions hosted by the GC Console.WriteLine("\nPartitions hosted by this global catalog:"); foreach (string partition in gc.Partitions) { Console.WriteLine("\t{0}", partition); } } catch (ActiveDirectoryObjectNotFoundException e) { // gc not found Console.WriteLine(e.Message); } }
public static void GCSample() { Console.WriteLine(); Console.WriteLine("<---------GLOBAL CATALOG INFO---------->\n"); // Find one global catalog within the current forest GlobalCatalog gc; try { gc = GlobalCatalog.FindOne(forestContext); Console.WriteLine("Finding one global catalog " + "in the current forest:"); Console.WriteLine("Name: {0}", gc); Console.WriteLine("Site: {0}", gc.SiteName); // roles held by the GC Console.WriteLine(); Console.WriteLine("Roles:"); foreach (ActiveDirectoryRole role in gc.Roles) { Console.WriteLine(role); } // partitions hosted by the GC Console.WriteLine(); Console.WriteLine("Partitions hosted by this global catalog:"); foreach (string partition in gc.Partitions) { Console.WriteLine(partition); } } catch (ActiveDirectoryObjectNotFoundException e) { // gc not found Console.WriteLine(e.Message); } Console.WriteLine(); }
public void TestForestGlobalCatalog() { using (Forest forest = Forest.GetForest(ActiveDirectoryContext)) { int count = 0; GlobalCatalogCollection gcCollection = forest.FindAllGlobalCatalogs(); foreach (GlobalCatalog gc in gcCollection) { count++; } Assert.True(count > 0); Assert.True(gcCollection.Contains(gcCollection[0])); Assert.Equal(0, gcCollection.IndexOf(gcCollection[0])); gcCollection = forest.FindAllGlobalCatalogs(forest.Sites[0].Name); count = 0; foreach (GlobalCatalog gc in gcCollection) { count++; } Assert.True(count > 0); Assert.True(gcCollection.Contains(gcCollection[0])); Assert.Equal(0, gcCollection.IndexOf(gcCollection[0])); GlobalCatalog globalCatalog = forest.FindGlobalCatalog(forest.Sites[0].Name); DirectoryContext forestContext = new DirectoryContext( DirectoryContextType.Forest, forest.Name, LdapConfiguration.Configuration.UserName, LdapConfiguration.Configuration.Password); Assert.Equal(globalCatalog.Name, GlobalCatalog.FindOne(forestContext, forest.Sites[0].Name).Name); } }