ActiveDirectory中:如何找到,如果域名? [英] ActiveDirectory: How to find if a domain is available?

查看:289
本文介绍了ActiveDirectory中:如何找到,如果域名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有发现如果一个域名在ActiveDirectory中使用可用之前GetDomain什么办法?我有一个应用程序,用户应该能够自行添加域,如果他们输入了一个无效域应该有一个错误。现在它被抓住下面的异常处理,但输入无效的域用户几乎不是一个特殊的情况发生,异常也可以采取一个很长的时间来抛出,特别是如果输入的IP地址(好像) 。有没有更好的解决方案呢?



 公共领域RegisterUserDirectory(字符串DOMAINID){
DirectoryContext背景=新DirectoryContext( DirectoryContextType.Domain,DOMAINID);

System.DirectoryServices.ActiveDirectory.Domain域;
尝试{
域= System.DirectoryServices.ActiveDirectory.Domain.GetDomain(背景);
}
赶上(ActiveDirectoryNotFoundException adne){
//句柄
}
赶上(例外五){
Log.Warning(无法联系域{0}:{1},DOMAINID,e.Message);
抛出;
}

...

}


解决方案

不幸的是,我认为没有真正的其他方式。试想想,你如何验证IP地址可达。所有你能做的就是尝试连接或发送ping请求。在此之后,你只需要等待,如果有人会回答,并且由于事实的连接可能是缓慢的超时高,你必须等待所有的时间。



所有你可以为更好的用户体验做的就是把这个工作变成另一胎(或后台工作),这样你的GUI仍然响应并显示一些进展或滚动字幕条给用户。然后,你还可以添加为用户通过简单地中止该线程取消连接试用的可能性。



因此,这不会让任何速度较快,但提供更好的响应给用户,并所以感觉最后更快


Is there any way of finding out if a domain is available in ActiveDirectory before using GetDomain? I have an app where users should be able to add domains by themselves, and if they enter an invalid domain there should be an error. Right now it is handled by catching the exception below, but a user entering an invalid domain is hardly an exceptional happening, and the exception also can take a really long time to get thrown, especially if an ip adress is entered (it seems like). Is there a better solution to this?

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

  ...
  ...
}

解决方案

Unfortunately i think there is no real other way. Just think about how you verify that an ip address is reachable. All you can do is try a connection or send an ping request. After this you just have to wait if someone will answer and due to the fact that the connection could be slow the timeouts are high and you have to wait all the time.

All you can do for a better user experience is to put this job into another tread (or background worker) so that your GUI is still responsive and showing some progress or marquee bar to the user. Then you could also add the possibility for the user to cancel the connection tryout by simply aborting this thread.

So this wouldn't make it any faster but give a better responsive to the user and so it feels faster at last.

这篇关于ActiveDirectory中:如何找到,如果域名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆