How to check if a Active Directory server is up and running using .Net?

不羁岁月 提交于 2019-12-21 04:51:47

问题


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.

How can I do that?


回答1:


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");
}


来源:https://stackoverflow.com/questions/324484/how-to-check-if-a-active-directory-server-is-up-and-running-using-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!