我在项目中遇到这样一段代码,使用了LDAP协议进行用户认证。起初,我以为是AD集成认证,后来又觉得不是。注意代码里LDAP的路径,有谁能告诉我,这里到底使用了什么产品进行用户认证的吗?报错信息里面的“LDAP Cil Account and Password”是何意思呢?protected void LoginButton_Click(object sender, EventArgs e)
{
string username = UsernameTextBox.Text;
string password = PasswordTextBox.Text; if (Request.ServerVariables["SERVER_NAME"].ToLower().Contains("alcatel-sbell"))
{
bool ldap = Authenticate(username, password);
if (!ldap)
{
this.errorInfo.Text = "<span style='color:Red'>Please check your LDAP Cil Account and Password!</span>";
return;
}
}
}private bool Authenticate(string username, string password)
{
bool authenticated = false;
try
{
string ldapPath = "172.24.198.80:389";
System.DirectoryServices.Protocols.LdapDirectoryIdentifier ldapID =
new System.DirectoryServices.Protocols.LdapDirectoryIdentifier(ldapPath); System.Net.NetworkCredential credential =
new System.Net.NetworkCredential(username, password);
System.DirectoryServices.Protocols.LdapConnection ldapCn =
new LdapConnection(ldapID, credential, AuthType.Basic); ldapCn.Bind();
authenticated = true;
} catch (Exception ex)
{
authenticated = false;
} return authenticated;
}
{
string username = UsernameTextBox.Text;
string password = PasswordTextBox.Text; if (Request.ServerVariables["SERVER_NAME"].ToLower().Contains("alcatel-sbell"))
{
bool ldap = Authenticate(username, password);
if (!ldap)
{
this.errorInfo.Text = "<span style='color:Red'>Please check your LDAP Cil Account and Password!</span>";
return;
}
}
}private bool Authenticate(string username, string password)
{
bool authenticated = false;
try
{
string ldapPath = "172.24.198.80:389";
System.DirectoryServices.Protocols.LdapDirectoryIdentifier ldapID =
new System.DirectoryServices.Protocols.LdapDirectoryIdentifier(ldapPath); System.Net.NetworkCredential credential =
new System.Net.NetworkCredential(username, password);
System.DirectoryServices.Protocols.LdapConnection ldapCn =
new LdapConnection(ldapID, credential, AuthType.Basic); ldapCn.Bind();
authenticated = true;
} catch (Exception ex)
{
authenticated = false;
} return authenticated;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货