在试图查询AD服务器,我想检查它是否是活蹦乱跳的。 貌似琐碎的事情,但我haven't发现任何阐明这一点。
Before trying to query the AD server I would like to check if it is alive and kicking. Looks like a trivial thing, but I haven´t found anything to elucidate this.
我怎么能这样做?
我只是试图让与正在运行的用户相关联的当前域方面:
I just try to get the current domain context associated with the running user:
try {
var domain = Domain.GetCurrentDomain();
/* Whatever i need from the domain */
} catch(ActiveDirectoryOperationException ex) {
MessageBox.Show("Cannot contact AD Server");
}
如果你想连接到另外一个领域,你可以试试:
If you want to connect to another domain you can try:
try {
var domain = Domain.GetDomain(
new DirectoryContext(DirectoryContextType.Domain, "mydomain.local"));
/* Whatever i need from the domain */
} catch(ActiveDirectoryOperationException ex) {
MessageBox.Show("Cannot contact AD Server");
}