在我开始之前,我已经访问Unknown Error (0x80005000) with LDAPS Connection并更改我的代码,虽然它确实解决了这个问题,似乎它有神秘地回来。错误0x80005000与LdapConnection和LDAPS
这里的好东西:
public static bool Authenticate(string username, string password, string domain)
{
bool authentic = false;
try
{
LdapConnection con = new LdapConnection(
new LdapDirectoryIdentifier(Host, Port));
if (IsSSL)
{
con.SessionOptions.SecureSocketLayer = true;
con.SessionOptions.VerifyServerCertificate = ServerCallback;
}
con.Credential = new NetworkCredential(username, password);
con.AuthType = AuthType.Basic;
con.Bind();
authentic = true;
}
catch (LdapException)
{
return false;
}
catch (DirectoryServicesCOMException)
{ }
return authentic;
}
public static bool IsSSL
{
get
{
return ConnectionString.ToLower().Contains("ldaps");
}
}
public static string ConnectionString
{
get
{
if (string.IsNullOrEmpty(_connectionString))
_connectionString = CompleteConfiguration.GetLDAPConnectionString();
return _connectionString;
}
set { _connectionString = value; }
}
public static int Port
{
get
{
var x = new Uri(ConnectionString);
int port = 0;
if (x.Port != -1)
{
port = x.Port;
}
else
{
port = x.OriginalString.ToLower().Contains("ldaps")
? 636
: 389;
}
return port;
}
}
public static string Host
{
get
{
var x = new Uri(ConnectionString);
return x.Host;
}
}
private static bool ServerCallback(LdapConnection connection, X509Certificate certificate)
{
return true;
}
这里是坏的东西: 当我尝试验证的应用程序,我碰到下面的错误,更确切地说,这是由con.Bind()触发线:
[收到COMException(0x80005000):未知的错误(0x80005000)] System.DirectoryServices.DirectoryEntry.Bind(布尔throwIfFail)378094 System.DirectoryServices.DirectoryEntry.Bind()36 System.DirectoryServices.DirectoryEntry。 get_NativeOb ject()+31 Complete.Authentication.GCAuthentication.Authenticate(String username,String password,String domain)in c:\ Builds \ 6 \ Idealink.Open.Pancanal \ Panama Canal \ Sources \ Idealink.Open \ Complete.Authentication \ GCAuthentication.cs:27 c:\ Builds \ 6 \ Idealink.Open.Pancanal \ Panama Canal \ Sources \ Idealink中的Complete.Authentication.AuthenticationFactory.ValidateUserLdap(String username,String password,String domain,Boolean isValid,String usernameWithDomain)。打开\ Complete.Authentication \ AuthenticationFactory.cs:93
这是相当混乱,因为它似乎有些用户帐户工作,而其他人不。但是,当我将上述代码放置在独立的测试环境中时,无论我使用哪个帐户,它都会成功。当我将它放回到带有ASP.NET和IIS的Windows 2008 R2服务器上时,它将失败,如上所述。尽管失败是一致的 - 账户始终失败或成功,从这个角度来看,没有任何随机性。
必须使用LDAPS和NOT LDAP访问LDAP服务器,这就是为什么我们不能使用DirectoryEntry对象 - LDAP服务器由客户端控制,因此无法以任何方式重新配置或更改。我们只是想在Web表单上捕获用户名/密码,然后在LDAP服务器上使用BIND来检查凭证。
我们正在使用.NET 3.5,目前无法升级,因此我恭敬地问,如果您的主要建议和参数要升级,请暂缓您的贡献。
谢谢,希望你能帮助
Karell,怎么是一个非常好的网站您连接到LDAP,您可以显示LDAP连接字符串,例如LDAP:// ... – MethodMan
示例'使用(DirectoryEntry de = new DirectoryEntry())de.Path =“LDAP:// yourSite/rootDSE”; de.Username = @“domain \ Karell”; de。密码=“密码”;}' – MethodMan
肯定的事情:LDAPS:// ServerAddress/OU = Users,DC = domain,DC = com - 我们没有在用户名上指定域名(从来没有问题, “工作”账户)。 –