我帮客户做了个内部网站,有个地方要求在界面上输入用户名和密码,然后判断输入的用户名和密码和域里的帐号和密码是否一样,我用的是LDAP协议,代码如下
public bool IsAuthenticated(string domain, string username, string pwd)
{
_path="LDAP://PTP";
string domainAndUsername = domain + @"\" + username;

DirectoryEntry entry = new DirectoryEntry( _path, 
domainAndUsername, pwd); try

//绑定到本机 AdsObject 以强制身份验证。 
Object obj = entry.NativeObject;
DirectorySearcher search = new DirectorySearcher(entry);
search.Filter = "(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result = search.FindOne();
if(null == result)
{
return false;
}
// 更新目录中的用户的新路径
_path = result.Path;
_filterAttribute = (String)result.Properties["cn"][0];
}
catch (Exception ex)
{
Response.Write(ex.Source.ToString());
Response.Write("<br>");
Response.Write(ex.Message.ToString());
Response.Write("<br>");
Response.Write(ex.ToString());return false;
}
return true;
}private void submit_Click(object sender, System.EventArgs e)
{
if(IsAuthenticated(Request.QueryString["Domain"],this.username.Text.ToString().Trim(),this.password.Text.ToString().Trim()))
{
.....
}在测试的时候很正常,可到了客户那里,一直出错,出错代码为
System.DirectoryServices从服务器返回了一个建议。System.Runtime.InteropServices.COMException (0x8007202B): 从服务器返回了一个建议。 at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) at System.DirectoryServices.DirectoryEntry.Bind() at System.DirectoryServices.DirectoryEntry.get_NativeObject() at jixiang.bbs.index.IsAuthenticated(String domain, String username, String pwd)
Q1:如果域不为xx.com的格式,而为PTP这种格式,LDAP://PTP这么写是否正确,如果不正确应该如何写?
Q2:上面的出错信息是什么意思?哪里出错了?会是什么原因导致的?
Q3:用LDAP协议是否一定要在服务器上装什么?我知道他们装了个AD,是否还需要装别的?
Q4:还在要IIS或者WEB。CONFIG上设置什么?IIS我已经设置了匿名访问的用户是域用户,但是不知道要把它加到哪个组里权限才够。
各位老大一定要鼎力相助啊,我都快疯了,如果解决了我一定另开贴送500分!