B
Brandon McCombs
Hello,
From my understanding, DirectoryEntry is used to connect to Active
Directory. Although this makes no sense whatsoever I accept it. The
problem is how am I supposed to test whether a connection is active or
not if I can create a DirectoryEntry with whatever data I want since the
data really isn't verified until I try to use it? I am not able to
determine whether the connection is really going to be available until
the Try {} block is reached below. Isn't there a way to determine before
then if the connection has been established? thanks
========================================================================
DirectoryEntry entry = null;
entry = new DirectoryEntry("LDAP://192.168.1.1/DC=mydomain,DC=com",
"(e-mail address removed)","Password",AuthenticationTypes.ServerBind);
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = ("(objectClass=*)");
mySearcher.SearchScope = SearchScope.Base;
Console.WriteLine("Active Directory Information");
Console.WriteLine("===========================================");
try {
SearchResultCollection results = mySearcher.FindAll();
foreach (SearchResult result in results) {
string searchpath = result.Path;
Console.WriteLine("path: {0}", searchpath);
ResultPropertyCollection rpc = result.Properties;
foreach (string property in rpc.PropertyNames) {
foreach (object value in rpc[property])
Console.WriteLine(" property={0} value={1}", property, value);
}
}
}
catch (System.Runtime.InteropServices.COMException ex) {
System.Console.WriteLine("Exception:" + ex.Message);
}
catch (System.InvalidOperationException ex1) {
System.Console.WriteLine("Exception::" + ex1.Message);
}
From my understanding, DirectoryEntry is used to connect to Active
Directory. Although this makes no sense whatsoever I accept it. The
problem is how am I supposed to test whether a connection is active or
not if I can create a DirectoryEntry with whatever data I want since the
data really isn't verified until I try to use it? I am not able to
determine whether the connection is really going to be available until
the Try {} block is reached below. Isn't there a way to determine before
then if the connection has been established? thanks
========================================================================
DirectoryEntry entry = null;
entry = new DirectoryEntry("LDAP://192.168.1.1/DC=mydomain,DC=com",
"(e-mail address removed)","Password",AuthenticationTypes.ServerBind);
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = ("(objectClass=*)");
mySearcher.SearchScope = SearchScope.Base;
Console.WriteLine("Active Directory Information");
Console.WriteLine("===========================================");
try {
SearchResultCollection results = mySearcher.FindAll();
foreach (SearchResult result in results) {
string searchpath = result.Path;
Console.WriteLine("path: {0}", searchpath);
ResultPropertyCollection rpc = result.Properties;
foreach (string property in rpc.PropertyNames) {
foreach (object value in rpc[property])
Console.WriteLine(" property={0} value={1}", property, value);
}
}
}
catch (System.Runtime.InteropServices.COMException ex) {
System.Console.WriteLine("Exception:" + ex.Message);
}
catch (System.InvalidOperationException ex1) {
System.Console.WriteLine("Exception::" + ex1.Message);
}