0

由于我看到了很多关于下面显示的异常的帖子,而且大多数人都痛苦地坚持了下来。

Exception Message: "The server is not operational"
Source: "System.DirectoryServices"

最近它发生在我身上。但最后我想通了。我想我应该在这里分享我的经验,以便将来对与我有同样问题的其他人有所帮助。

我正在使用的程序正在使用 AD 身份验证。它在我属于 AD 域的计算机上运行良好。代码如下。

 public static bool IsAuthenticated(string srvr, string usr, string pwd)
        {
            bool authenticated = false;

            try
            {
                DirectoryEntry deRoot = new DirectoryEntry(srvr);

                DirectoryEntry entry = new DirectoryEntry(srvr, usr, pwd);
                object nativeObject = entry.NativeObject;//this will cause exception Until setting the right DNS address.
                authenticated = true;
            }
            catch (DirectoryServicesCOMException cex)
            {
                //not authenticated; reason why is in cex
                HttpContext.Current.Response.Write(cex.Message);
            }
            catch (Exception ex)
            {
                //not authenticated due to some other exception [this is optional]
                HttpContext.Current.Response.Write(ex.Message);
            }

            return authenticated;
        }

有一天,我们的 IT 环境要求发生了变化,我的电脑 IP 从 10.50.70.64 切换到了 169.254.135.249。因为我的网卡IP和DNS总是设置为Obtain address automatically.在这种情况下,我可以使用AD帐户成功登录我的电脑。但是程序运行时出现了一个很大的异常。所以我怀疑我的网络适配器设置是否有问题。最后我发现如果我为我们的 IT 环境设置了正确的 DNS 地址。异常消失了。我不知道为什么。所以我也希望有人能解释一下。谢谢。

4

1 回答 1

0

在 AD 域中验证用户和密码之前,需要针对 DSN 服务器解析域路径。

于 2012-11-01T05:10:18.637 回答