【发布时间】:2017-07-10 12:59:24
【问题描述】:
我正在使用 asp.NET MVC5 网站对 Active Directory 中的用户进行研究。当我进行无效搜索时(例如'"éééézztaaz'),ArgumentException 不断被抛出,但我不明白。这是我的搜索方法:
public List<ADProperties> SearchUserByName(string name)
{
//ADProperties is a POCO to store values retrieved
try
{
List<ADProperties> theListIWant = new List<ADProperties>();
//createDirectoryEntry() is a method to establish a connection to Active Directory
DirectoryEntry ldapConnection = createDirectoryEntry();
DirectorySearcher search = new DirectorySearcher(ldapConnection);
//Search filter to find users
search.Filter = "(&(objectClass=user)(anr=" + name + "))";
///Properties to load
search.PropertiesToLoad.Add("objectSID");
search.PropertiesToLoad.Add("displayName");
search.PropertiesToLoad.Add("distinguishedName");
resultCollection = search.FindAll();
//ArgumentException at if statement
//I put this to AVOID exceptions, then in my controller, if value is null
//I return a different view
if (resultCollection==null ||resultCollection.Count==0)
{
return null;
}
}
else
{ //Do stuff and return
return theListIWant;
}catch(ActiveDirectoryOperationException e)
{
Console.WriteLine("Active Directory Operation Exception caught: " + e.ToString());
}
return null;
}
确切的例外是:
搜索过滤器 (&(objectClass=user)(anr=)) 无效
(从法语翻译)
所以我不明白。我添加了条件以避免抛出异常,但显然它没有帮助。
【问题讨论】:
标签: c# asp.net-mvc active-directory