我正在使用System.DirectoryServices.AccountManagement接口绑定到一个AD-LDS实例。我对AD-LDS实例中本地存在的用户使用简单绑定。当我在托管AD-LDS的服务器上运行客户端时,它可以工作,但当我在远程计算机上运行客户端时,它不能工作。
这是我用来绑定和搜索用户的代码:
var c = new PrincipalContext(ContextType.ApplicationDirectory, "fullhostname:50001", "CN=Users,DC=app,DC=local", ContextOptions.SimpleBind, "CN=joe,CN=Users,DC=app,DC=local", "abc");
var u = UserPrincipal.FindByIdentity(c, IdentityType.Name, "john");这是当我在远程计算机上运行它时抛出的异常:
System.DirectoryServices.AccountManagement.PrincipalServerDownException: The server is not operational.
---> 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.DirectoryEntry.get_Options()
at System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInit()
--- End of inner exception stack trace ---
at System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInit()
at System.DirectoryServices.AccountManagement.PrincipalContext.DoApplicationDirectoryInit()
at System.DirectoryServices.AccountManagement.PrincipalContext.Initialize()
at System.DirectoryServices.AccountManagement.PrincipalContext.get_ConnectedServer()
at MyApplication.DiagnosticsController.TryAdLdsSettings(AdLdsData data) in C:\code\MyApplication\DiagnosticsController.cs:line 166如果我使用System.DirectoryServices应用程序接口,它也可以在远程计算机上运行:
var obj = new DirectoryEntry("LDAP://fullhostname:50001/CN=Users,DC=app,DC=local", "CN=joe,CN=Users,DC=app,DC=local",
"abc", AuthenticationTypes.None);
obj.RefreshCache();这是可行的,但我需要使用System.DirectoryServices.AccountManagement API。
有人知道哪里出了问题吗?
发布于 2016-03-01 00:10:33
我能够让它在一个域上工作,只需做一些小改动,我希望这些技巧能有所帮助。
"CN=joe,CN=Users,DC=app,DC=local",应该是完全限定的用户名,而不是LDAP路径;这通常看起来像COMPUTER-NAME\\joe (无论您的计算机是什么名称),或者如果您像我一样在一个域中,则看起来像DOMAIN-NAME\\joe。(如果fullhostname不是您的本地工作站,那么您可能在一个域中,或者您可能需要指定fullhostname\joe来请求针对主机服务器而不是您的本地服务器的身份验证,因为您的本地凭据可能在主机服务器上不起作用)。ContextType.ApplicationDirectory更改为ContextType.Domain;听起来您不在域中,因此您可能需要ContextType.ApplicationDirectory,但错误消息使我认为Active Directory服务不是running.:50001高到足以被阻止,请确保您没有阻止请求的防火墙软件,无论是从您的计算机传出,还是传入"fullhostname“计算机;当然,还要确保您的active directory服务实际上在50001上可用,而不是其他身份验证协议。发布于 2016-03-08 00:23:28
我最终重写了PrincipalContext和UserIdentity的用法,直接使用DirectoryEntry。我花了几个小时为我需要的方便的UserIdentity函数找到适当的重新实现,但在这样做之后,一切都运行得很好。
这对我来说是一个相当神秘的问题,为什么会发生在第一个地方。我唯一的猜测是,在我的特定配置中,我的特定版本的AD LDS在底层库中的某个地方有一个bug。直接在DirectoryEntry中重写所有内容,让所有内容与我所知道的完全相似,解决了这个问题。
https://stackoverflow.com/questions/30194369
复制相似问题