以下に示す例外についての投稿をたくさん見たので、ほとんどの人はそれで立ち往生していました。
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アドレスを設定したかどうかを見つけました. 例外はなくなりました。どうしてか分かりません。ですから、誰かがそれについてもっと説明できることも願っています。ありがとう。