[英]Get Global Catalog for a given LDAP server
Question first, explanation later: How can I get the GC server for any given LDAP server? 首先是问题,稍后是解释: 如何获得给定LDAP服务器的GC服务器?
To understand my needs, let me explain: 为了理解我的需求,让我解释一下:
I had to extend Henning Krause's ExchangeAddressListService (I am not sure whether I should/may c'n'p all of Henning's code into this post?) to get useful debug output: 我必须扩展Henning Krause的ExchangeAddressListService (我不确定是否应该/可以将Henning的所有代码都放到这篇文章中吗?)以获得有用的调试输出:
private DirectoryEntry GetDirectoryEntry(string path, string protocol)
{
var ldapPath = string.IsNullOrEmpty(path) ? string.Format("{0}:", protocol) : string.Format("{0}://{1}", protocol, path);
dbg.Add("Getting DirectoryEntry for path " + ldapPath);
return new DirectoryEntry(ldapPath);
}
public ActiveDirectoryConnection(Debug dbg)
{
this.dbg = dbg;
}
and to allow for selection of a certain domain: 并允许选择某个域:
internal AddressList(string path, ActiveDirectoryConnection connection, string domain)
{
_Path = path;
_Connection = connection;
_Domain = domain;
}
... ...
private IEnumerable<AddressList> GetAddressLists(string containerName)
{
string exchangeRootPath;
using (var root = _Connection.GetLdapDirectoryEntry(_Domain+"/RootDSE"))
...
foreach (SearchResult addressBook in searchResultCollection)
{
yield return
new AddressList((string)addressBook.Properties["distinguishedName"][0], _Connection, _Domain);
}
...
}
Now I have a problem with the domain because it seems as if for some domains SOMEDOMAIN
the Global Catalog cannot be accessed via GC://SOMEDOMAIN
. 现在我对域有问题,因为似乎对于某些域
SOMEDOMAIN
,无法通过GC://SOMEDOMAIN
访问全局目录。 This is my code I use: 这是我使用的代码:
var domain = User.Identity.Name.Split('\\')[0]; // SOMEDOMAIN\SomeUser -> Domain is SOMEDOMAIN
dbg.Add("User NETBIOS domain is "+domain);
AddressListService addressListService = new ExchangeAddressListService(connection,domain);
IEnumerable<AddressList> addressLists = addressListService.GetGlobalAddressLists();
AddressList addressList = addressLists.First()
try {
IEnumerable<SearchResult> searchResults = addressList.GetMembers("displayName", "distinguishedname", "mail")
} catch(Exception e) {
dbg.Add("Error in GetMembers: "+e.Message);
return new AjaxAnswer(dbg.Flush());
}
It produces the error log: 它产生错误日志:
User NETBIOS domain is SOMEDOMAIN
Getting DirectoryEntry for path LDAP://SOMEDOMAIN/RootDSE
Getting DirectoryEntry for path LDAP://CN=Microsoft Exchange, CN=Services, CN=Configuration,DC=somedomain,DC=net
Getting DirectoryEntry for path LDAP://CN=All Global Address Lists,CN=Address Lists Container, CN=MYMAIL,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=somedomain,DC=net
Getting DirectoryEntry for path LDAP://CN=Default Global Address List,CN=All Global Address Lists,CN=Address Lists Container,CN=MYMAIL,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=somedomain,DC=net
Getting DirectoryEntry for path GC://SOMEDOMAIN
Error in GetMembers: The server is not operational.
Not all DC are GC. 并非所有DC都是GC。 So
GC://SOMEDOMAIN
may fail if SOMEDOMAIN
is not a GC. 因此,如果
SOMEDOMAIN
不是GC, GC://SOMEDOMAIN
可能会失败。
In my project, I use the DsGetDcName Win32 function to discover the GC. 在我的项目中,我使用DsGetDcName Win32函数来发现GC。
Details of DsGetDcName function: DsGetDcName函数的详细信息:
http://msdn.microsoft.com/en-us/library/ms675983%28v=vs.85%29.aspx http://msdn.microsoft.com/en-us/library/ms675983%28v=vs.85%29.aspx
See below for how to pinvoke the call: 请参阅以下有关如何拨通呼叫的电话:
http://www.pinvoke.net/default.aspx/netapi32.dsgetdcname http://www.pinvoke.net/default.aspx/netapi32.dsgetdcname
As I know System.DirectoryServices.ActiveDirectory
also provide classes to handle GC. 据我所知
System.DirectoryServices.ActiveDirectory
还提供了用于处理GC的类。
eg Forest.GlobalCatalogs
例如
Forest.GlobalCatalogs
I already use the DsGetDcName function, so never tried this before. 我已经使用了DsGetDcName函数,所以以前从未尝试过。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.