我想使用我的MVC应用程序连接到LDAP服务器。我不想使用活动目录。 当我从用户那里获得用户名和密码时,这是我的post方法:
[HttpPost]
public ActionResult Login(Login model, string returnUrl)
{
string pwd = model.password;
System.Security.Cryptography.MD5 hs = System.Security.Cryptography.MD5.Create();
byte[] db = hs.ComputeHash(System.Text.Encoding.UTF8.GetBytes(pwd));
string result = Convert.ToBase64String(db);
var BuildServerName = new StringBuilder();
BuildServerName.Append("172.16.1.98");
// setup an ldapconnection to that endpoint
var ldapConnection = new LdapConnection(BuildServerName.ToString());
// it looks like you have an administrative account to bind with, so use that here
var networkCredential = new NetworkCredential(model.username, result, "dc=mnit,dc=ac,dc=in");
// set the following to true if it's over ssl (636), if not just set it to false
ldapConnection.SessionOptions.VerifyServerCertificate += delegate { return true; };
// now set your auth type - I typically use 'negotiate' over LDAPS, and `simple` over LDAP
// for this example we'll just say you're not using LDAPS
ldapConnection.AuthType = AuthType.Basic;
ldapConnection.SessionOptions.ProtocolVersion = 3;
ldapConnection.Bind(networkCredential);
它在ldapConnection.Bind(networkCredential);
处抛出一个错误,即:可分辨名称包含无效语法。我该怎么做呢
当我将BuildServerName.Append("172.16.1.98");
更改为BuildServerName.Append("LDAP://172.16.1.98");
时,会返回错误
LDAP服务器不可用。
ldapConnection.Bind(networkCredential);
。有没有其他方法可以通过ldap连接和检查用户名和密码