- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 Windows 服务,它通过 WCF 向 Windows 窗体应用程序提供数据。该服务还负责用户身份验证,通过公司 Active Directory 服务器使用 LDAP 验证用户密码。
问题是它可以工作数周(甚至数月),然后发生某些事情并且 LDAP 用户身份验证失败并出现以下异常,直到我重新启动服务:
System.DirectoryServices.AccountManagement.PrincipalServerDownException: The server could not be contacted.
---> System.DirectoryServices.Protocols.LdapException: The LDAP server is unavailable.
at System.DirectoryServices.Protocols.LdapConnection.Connect()
at System.DirectoryServices.Protocols.LdapConnection.SendRequestHelper(DirectoryRequest request, Int32& messageID)
at System.DirectoryServices.Protocols.LdapConnection.SendRequest(DirectoryRequest request, TimeSpan requestTimeout)
at System.DirectoryServices.Protocols.LdapConnection.SendRequest(DirectoryRequest request)
at System.DirectoryServices.AccountManagement.PrincipalContext.ReadServerConfig(String serverName, ServerProperties& properties)
--- End of inner exception stack trace ---
at System.DirectoryServices.AccountManagement.PrincipalContext.ReadServerConfig(String serverName, ServerProperties& properties)
at System.DirectoryServices.AccountManagement.PrincipalContext.DoServerVerifyAndPropRetrieval()
at System.DirectoryServices.AccountManagement.PrincipalContext..ctor(ContextType contextType, String name, String container, ContextOptions options, String userName, String password)
at System.DirectoryServices.AccountManagement.PrincipalContext..ctor(ContextType contextType, String name, String userName, String password)
at SMSTModel.Authentication.ActiveDirectory.IsUserAllowed(String username, String password)
public static bool IsUserAllowed(string username, string password)
{
String localDomain = Domain.GetComputerDomain().Name;
string userDomain = null;
string user = username;
if (user.Contains(@"\"))
{
userDomain = user.Substring(0, user.IndexOf("\\"));
user = user.Substring(user.IndexOf("\\") + 1);
}
userDomain = userDomain != null ? userDomain : localDomain;
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, userDomain, user, password))
{
bool credOk = pc.ValidateCredentials(user, password);
if (!credOk)
return false;
using (UserPrincipal userP = UserPrincipal.FindByIdentity(pc, user))
{
if (userP != null)
{
using (PrincipalContext pc1 = new PrincipalContext(ContextType.Domain, localDomain))
{
using (GroupPrincipal groupPrincipal = new GroupPrincipal(pc1))
{
groupPrincipal.Name = "APP_*";
using (PrincipalSearcher principalSearcher = new PrincipalSearcher(groupPrincipal))
foreach (Principal found in principalSearcher.FindAll())
{
if (found.Name == "APP_Group" && found is GroupPrincipal && userP.IsMemberOf((GroupPrincipal)found))
{
return true;
}
}
}
}
}
}
}
return false;
}
最佳答案
看起来这里发生了异常:
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, userDomain, user, password))
userDomain
正在使用的是?看起来您的环境中可能有多个域,那么您的所有域都会发生这种情况,还是只有一个域?
nslookup example.com
关于c# - Windows 服务 LdapException : The LDAP server is unavailable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57321596/
我正在使用 unboundid ldap sdk 来执行 ldap 查询。运行 ldap 搜索查询时遇到一个奇怪的问题。当我对包含 50k 个条目的组运行查询时出现异常。我的异常(exception)
我们围绕 LDAP 对客户端进行了新的增强,以使用 userPrincipalName 启用登录。 .他早些时候使用 sAMAccountName用于登录。当用户尝试在他的测试环境中测试应用程序时,他
我有一个 Windows 服务,它通过 WCF 向 Windows 窗体应用程序提供数据。该服务还负责用户身份验证,通过公司 Active Directory 服务器使用 LDAP 验证用户密码。 问
我正在尝试通过 Mono(版本 2.10.8.1 和 3.0.6)在 debian 上使用 Exchange EWS 2我正在使用 vs2012 在 Windows 8 上进行开发。 该程序在 Win
我正在尝试制作一个 Android 应用程序以连接到 LDAP 服务器。我正在使用 UnboundId 库,因此我的应用程序能够建立 LDAP 连接。问题是resultCode 91-connecti
我在 Java 中搜索 LDAP 时遇到以下异常。它获取许多记录,但最后抛出以下异常。 netscape.ldap.LDAPException: error result (4); Sizelimit
我是一名优秀的程序员,十分优秀!