System.Runtime.InteropServices.COMException (0x80005000): Unknown error (0x80005000)
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_AdsObject()
at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
at System.DirectoryServices.DirectorySearcher.FindOne()
作为控制台应用程序中的摘要,这起作用。但是,当我作为WCF服务的一部分运行(在同一凭据下运行)时,它会引发上述异常。 任何建议?
thanks
我一次又一次地拥有同样的事情,似乎没有任何帮助。
将路径从
ldap://
LDAP://
这是一个许可问题。当您运行控制台应用程序时,该应用程序将使用您的凭据运行,例如为“你” WCF服务在哪里运行?在IIS?最有可能的是,它在一个单独的帐户下运行,该帐户未许可查询Active Directory。
您可以尝试使WCF模仿Thingie工作,以便您自己的凭据传递,或者您可以在创建您的DirectoryEntry时指定用户名/密码:
DirectorySearcher directorySearcher = new DirectorySearcher(directoryEntry);
directorySearcher.Filter = string.Format("(&(objectClass=user)(objectCategory=user) (sAMAccountName={0}))", username);
directorySearcher.PropertiesToLoad.Add("msRTCSIP-PrimaryUserAddress");
var result = directorySearcher.FindOne();
if(result != null)
{
if(result.Properties["msRTCSIP-PrimaryUserAddress"] != null)
{
var resultValue = result.Properties["msRTCSIP-PrimaryUserAddress"][0];
}
}
ok,因此毕竟这可能不是凭据(通常在我看到的80%以上的情况下是这种情况)。
如何更改代码?DirectorySearcher
我的想法是:为什么不立即告诉您您对什么属性?然后,您无需再付出额外的步骤即可从搜索结果中获取完整的
DirectoryEntry
(应该更快),并且由于您告诉目录搜索者查找该属性,因此肯定会加载到搜索结果中 - 因此,除非它是零(没有值集),否则您应该能够轻松地检索它。marc
在Ektron的上下文中,通过在Windows中安装“ IIS6 Metabase兼容性”功能来解决此问题:
IIS6 metabase的检查检查“ Windows功能”或“角色服务” 兼容性,如果丢失了:
ref:https://portal.ektron.com/kb/1088/
i有相同的错误 - 在我的情况下,这是路径参数的额外斜线,这使差异有所不同。 bad:
DirectoryEntry directoryEntry = new DirectoryEntry("LDAP://someserver.contoso.com/DC=contoso,DC=com/", userName, password);
好:
DirectoryEntry directoryEntry =
new DirectoryEntry("LDAP://someserver.contoso.com/DC=contoso,DC=com",
userName, password);
将我指向正确的方向。 最后,在使用之前对每个路径值呼叫仅供参考,我有相同的错误,并且使用了正确的凭据,但我的LDAP URL是错误的:(
在我居住的公司的生产系统中遇到了这个问题...一个使LDAP绑定在IP更改后停止工作的网页。
解决方案... ...我安装了基本身份验证以执行此处指示的故障排除:Https://support.microsoft.com/en-us/kb/329986 之后,事情刚刚开始工作。即使我在测试页面中重新删除了基本身份验证,所有其他页面也开始使用Windows Authentication。
阿卡西奥
如果物理机器的内存不足,可能会发生这种错误。 就我而言,我在IIS上托管了一个试图访问广告的站点,但是服务器已经用完了。
DirectoryEntry entry = new DirectoryEntry(path, ldapUser, ldapPassword);
DirectorySearcher searcher = new DirectorySearcher();
searcher.SearchRoot = entry;
searcher.SearchScope = SearchScope.Subtree;
在我的情况下,问题是我正在尝试引用目录的属性价值,即使该目录enteryentry根本没有该属性。 例如,如果您有:
var myGroup = new DirectoryEntry("LDAP://CN=mygroup,OU=mydomain....", myUsername, myPassword);
var groupManager = myGroup.Properties["managedBy"].Value.ToString();
如果在DirectoryEntry.patch中,则在符号“ ldap //:”之后发生相同的错误。有必要在DirectorySearcher.findone()之前检查DirectoryEntry.path。除非明确指定的域,否则不需要“ ldap://”。
private void GetUser(string userName, string domainName)
{
DirectoryEntry dirEntry = new DirectoryEntry();
if (domainName.Length > 0)
{
dirEntry.Path = "LDAP://" + domainName;
}
DirectorySearcher dirSearcher = new DirectorySearcher(dirEntry);
dirSearcher.SearchScope = SearchScope.Subtree;
dirSearcher.Filter = string.Format("(&(objectClass=user)(|(cn={0})(sn={0}*)(givenName={0})(sAMAccountName={0}*)))", userName);
var searchResults = dirSearcher.FindAll();
//var searchResults = dirSearcher.FindOne();
if (searchResults.Count == 0)
{
MessageBox.Show("User not found");
}
else
{
foreach (SearchResult sr in searchResults)
{
var de = sr.GetDirectoryEntry();
string user = de.Properties["SAMAccountName"][0].ToString();
MessageBox.Show(user);
}
}
}
在我的类似问题上每天都有一天,但是所有这些答案都没有帮助。 在我的情况下,我没有在IIS设置中启用Windows身份验证...