作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
在使用 GetDomain 之前,有什么方法可以查明某个域在 ActiveDirectory 中是否可用?我有一个应用程序,用户应该能够自己添加域,如果他们输入无效的域,应该会出现错误。现在它是通过捕获下面的异常来处理的,但是用户输入无效域几乎不是异常事件,并且异常也可能需要很长时间才能被抛出,尤其是如果输入了 ip 地址(看起来像) .对此有更好的解决方案吗?
public Domain RegisterUserDirectory(string domainId) {
DirectoryContext context = new DirectoryContext(DirectoryContextType.Domain, domainId);
System.DirectoryServices.ActiveDirectory.Domain domain;
try {
domain = System.DirectoryServices.ActiveDirectory.Domain.GetDomain(context);
}
catch (ActiveDirectoryNotFoundException adne) {
// handle
}
catch (Exception e) {
Log.Warning("Failed to contact domain {0}: {1}", domainId, e.Message);
throw;
}
...
...
}
最佳答案
我能想到的唯一其他选择是使用林来枚举域。即
var myDomain = Domain.GetCurrentDomain(); //or .GetComputerDomain();
var forestDomains = myDomain.Forest.Domains;
这假设您想要的所有域都在同一个林中。然后,您需要针对此集合测试用户输入的 domainId
,可能针对每个域 .Name
属性进行测试。
关于c# - 事件目录 : How to find if a domain is available?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4666334/
我是一名优秀的程序员,十分优秀!