Server_Name :servername.cloudapp.net
IP_Address : x.x.x.x
Protocol_Type : Recursive LDAP
LDAP_Port : 389
User_OU : xxx.xxx.world.local/city/city Projects/city Worksheet/CityUsers
Domain : xxx.xxx.world.local
Service_Account : city\serviceaccountname
Svc_Credentials : serviceaccountpwd
使用上述详细信息我尝试使用ldap连接到活动目录服务帐户,但我无法连接并验证输入的用户凭据。
应用程序包含一个登录屏幕,用户可以在其中输入他/她的用户名和密码,提供的用户名和密码应在活动目录中进行身份验证。
请帮助我建立与活动目录服务帐户的连接,并验证输入的用户凭据。
请在下面找到用于身份验证的代码:
public void Autherize(User user)
{
DirectoryEntry de = new DirectoryEntry("LDAP://IP_Address:LDAP Port/OU=CityUsers,OU=city Worksheet,OU=city Projects,OU=city,DC=xxx,DC=xxx,DC=world,DC=local", "city\serviceaccountname", "serviceaccountpwd");
DirectorySearcher ds = new DirectorySearcher(de);
try
{
SearchResult result = ds.FindOne();
if (result != null)
{
foreach (string propName in result.Properties.PropertyNames)
{
foreach (object myCollection in result.Properties[propName])
{
Debug.WriteLine(propName + " : " + myCollection.ToString());
}
}
}
else
Debug.WriteLine("Error: Not found");
}
catch (Exception f)
{
Debug.WriteLine("Error:" + f.Message);
}
}