(&(objectCategory=user)(|(CN=)(sAMAccountName=))) 搜索过滤器无效。
有人可以告诉我在什么情况下会出现此错误?
我正在尝试通过 Visual Studio 发布我的 Web 应用程序。我在本地主机上运行良好,但发布后出现此错误。
public static string[] ldapUserQuery(string userName, string[] desiredProps)
{
// Establishes path for query. In this case sap.corp
string queryPath = "LDAP://DC=SAP,DC=CORP";
// Used to establish desiredProps from within the function, but now it can be passed in.
// This was kept in here as an example of what the desiredProps should look like when
// passing it in.
//
// Desired pros are the LDAP attributes to be returned.
/*
string[] desiredProps = new string[]
{
//"givenName", // first name
//"sn", // last name
//"mail" // email
};
*/
// establishes the proper length of the array to be returned.
string[] returnVal = new string[desiredProps.Length];
// Creates objects for performing the Query.
DirectoryEntry dirEntry = new DirectoryEntry();
DirectorySearcher dirSearcher = new DirectorySearcher();
SearchResult result;
// dirEntry is used for establishing the connection for the query
dirEntry.Path = queryPath;
dirEntry.AuthenticationType = AuthenticationTypes.Secure;
// dirSearcher is the query itself.
dirSearcher.SearchRoot = dirEntry;
dirSearcher.Filter = string.Format("(&(objectCategory=user)(|(CN={0})(sAMAccountName={0})))", userName);
// executes the query.
result = dirSearcher.FindOne();
// handle the result of the query.
if (result != null)
{
// if the query was successful, then dig through the returned information
// and set found objects that match the desiredProps to the returnVal object.
for (int i = 0; i < desiredProps.Length; i++)
{
// if the desiredProps has a bad attribute name, just give it the placeholder
// and move along.
if (result.Properties[desiredProps[i]] != null)
{
returnVal[i] = result.GetDirectoryEntry().Properties[desiredProps[i]].Value.ToString();
}
//else
//{
// returnVal[i] = GlobalVars.placeHolder;
//}
}
}