我对 C# 中的 Active Directory 类有疑问。在我的程序中的某一时刻,我正在尝试使用以下命令获取用户登录的当前域:
Domain.GetCurrentDomain();
大多数时候,它有效。但是从无线笔记本电脑执行时,它给了我以下错误:
System.DirectoryServices.ActiveDirectory.ActiveDirectoryServerDownException: The server is not operational.
Name: "DOMAIN.ca"
---> System.Runtime.InteropServices.COMException: The server is not operational.
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_AdsObject()
at System.DirectoryServices.PropertyValueCollection.PopulateList()
at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName)
at System.DirectoryServices.PropertyCollection.get_Item(String propertyName)
at System.DirectoryServices.ActiveDirectory.PropertyManager.GetPropertyValue(DirectoryContext context, DirectoryEntry directoryEntry, String propertyName)
--- End of inner exception stack trace ---
at System.DirectoryServices.ActiveDirectory.PropertyManager.GetPropertyValue(DirectoryContext context, DirectoryEntry directoryEntry, String propertyName)
at System.DirectoryServices.ActiveDirectory.Domain.GetDomain(DirectoryContext context)
at System.DirectoryServices.ActiveDirectory.Domain.GetCurrentDomain()
at ADT.ADTools.ComputerIsInDomain()
在我的特定情况下,这段代码应该适用于登录 Active Directory 帐户的任何帐户,无论它正在运行的计算机是什么,或者计算机是否使用无线或有线连接连接到域。
你们中有人知道该问题的答案或我可以采取的任何解决方法吗?