【问题标题】:How to check if a Active Directory server is up and running using .Net?如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行?
【发布时间】:2008-11-27 19:00:49
【问题描述】:

在尝试查询 AD 服务器之前,我想检查它是否还活着并且正在运行。 看起来是一件微不足道的事情,但我还没有找到任何可以解释这一点的东西。

我该怎么做?

【问题讨论】:

    标签: .net active-directory ldap


    【解决方案1】:

    我只是尝试获取与正在运行的用户关联的当前域上下文:

    try {
        var domain = Domain.GetCurrentDomain();
        /* Whatever i need from the domain */
    } catch(ActiveDirectoryOperationException ex) {
        MessageBox.Show("Cannot contact AD Server");
    }
    

    如果你想连接到另一个域,你可以尝试:

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

    【讨论】:

    • 只有在运行代码的机器实际登录到该域时才会起作用(不一定是这种情况)。
    • 我试图避免使用 try/catch 结构,但这样就可以了!
    • #get the current domain: 我收到异常“当前安全上下文未与 Active Directory 域或林关联。”我的电脑应该加入域吗?
    猜你喜欢
    • 2017-02-16
    • 2011-07-10
    • 2014-01-18
    • 1970-01-01
    • 2022-01-25
    • 2021-04-09
    • 1970-01-01
    • 2012-02-17
    • 1970-01-01
    相关资源
    最近更新 更多