Pra*_*dit 0 c# asp.net active-directory
(&(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;
//}
}
}
Run Code Online (Sandbox Code Playgroud)
(&(objectCategory=user)(|(CN=)(sAMAccountName=)))是无效的,因为它不知道您要比较的CN属性和sAMAccountName属性.
(&(objectCategory=user)(|(CN=something)(sAMAccountName=someName)))已验证.用对你有意义的东西替换某些东西和someName.
| 归档时间: |
|
| 查看次数: |
9670 次 |
| 最近记录: |