C# 4.0 仅使用用户名从广告中获取用户信息
我有以下代码C# 4.0 仅使用用户名从广告中获取用户信息,c#-4.0,authentication,active-directory,C# 4.0,Authentication,Active Directory,我有以下代码 private static string ADValidateUser(string LDAP_URL, string username, string password) { System.DirectoryServices.DirectoryEntry myDE = new System.DirectoryServices.DirectoryEntry(LDAP_URL, username, password); Direc
private static string ADValidateUser(string LDAP_URL, string username, string password)
{
System.DirectoryServices.DirectoryEntry myDE = new System.DirectoryServices.DirectoryEntry(LDAP_URL, username, password);
DirectorySearcher mySearcher = new DirectorySearcher(myDE);
mySearcher.Filter = ("sAMAccountName=" + username);
try
{
SearchResult myresult = mySearcher.FindOne();
string strName = myresult.GetDirectoryEntry().Properties["displayname"].Value.ToString();
string strCompany = myresult.GetDirectoryEntry().Properties["company"].Value.ToString();
return ("TRUE|" + (strName + ("|" + strCompany)).ToUpper());
}
catch (Exception ex)
{
return "FALSE|None";
}
}
我需要修改此方法以获取指定的用户信息,而不使用密码,而只使用用户名
谢谢。这会起作用,但假设此进程以有权访问LDAP\u URL中指定目录的用户身份运行 本质上,更改是调用DirectoryEntry。。。构造函数,并省略使用当前用户的用户名和密码
private static string ADValidateUser(string LDAP_URL, string username)
{
System.DirectoryServices.DirectoryEntry myDE = new System.DirectoryServices.DirectoryEntry(LDAP_URL);
DirectorySearcher mySearcher = new DirectorySearcher(myDE);
mySearcher.Filter = ("sAMAccountName=" + username);
try
{
SearchResult myresult = mySearcher.FindOne();
string strName = myresult.GetDirectoryEntry().Properties["displayname"].Value.ToString();
string strCompany = myresult.GetDirectoryEntry().Properties["company"].Value.ToString();
return ("TRUE|" + (strName + ("|" + strCompany)).ToUpper());
}
catch (Exception ex)
{
return "FALSE|None";
}
}