Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# (&;(objectCategory=user)(|(CN=)(sAMAccountName=))搜索筛选器无效_C#_Asp.net_Active Directory - Fatal编程技术网

C# (&;(objectCategory=user)(|(CN=)(sAMAccountName=))搜索筛选器无效

C# (&;(objectCategory=user)(|(CN=)(sAMAccountName=))搜索筛选器无效,c#,asp.net,active-directory,C#,Asp.net,Active Directory,(&(objectCategory=user)(|(CN=)(sAMAccountName=))搜索筛选器为 无效 有人能告诉我在什么情况下会出现这个错误吗 我正试图通过VisualStudio发布我的web应用程序。我在本地主机上运行正常,但在发布后出现此错误 public static string[] ldapUserQuery(string userName, string[] desiredProps) { // Establishes path for q

(&(objectCategory=user)(|(CN=)(sAMAccountName=))搜索筛选器为 无效

有人能告诉我在什么情况下会出现这个错误吗

我正试图通过VisualStudio发布我的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;
                //}
            }
        }
公共静态字符串[]ldapUserQuery(字符串用户名,字符串[]desiredProps)
{
//为查询建立路径。在本例中为sap.corp
字符串queryPath=“LDAP://DC=SAP,DC=CORP”;
//用于从函数中建立所需的道具,但现在可以传入。
//这是保存在这里的一个示例,说明了当
//把它传进来。
//
//所需的pros是要返回的LDAP属性。
/*
字符串[]desiredProps=新字符串[]
{
//“givenName”,//名字
//“sn”,//姓
//“邮件”//电子邮件
};
*/
//建立要返回的数组的正确长度。
string[]returnVal=新字符串[desiredProps.Length];
//创建用于执行查询的对象。
DirectoryEntry dirEntry=new DirectoryEntry();
DirectorySearcher dirsearch=新的DirectorySearcher();
搜索结果;
//dirEntry用于建立查询的连接
dirEntry.Path=queryPath;
dirEntry.AuthenticationType=AuthenticationTypes.Secure;
//dirSearcher是查询本身。
dirSearcher.SearchRoot=dirEntry;

dirSearcher.Filter=string.Format(&(objectCategory=user)(CN={0})(sAMAccountName={0})),用户名); //执行查询。 结果=dirSearcher.FindOne(); //处理查询的结果。 如果(结果!=null) { //如果查询成功,则仔细查看返回的信息 //并将找到的与desiredProps匹配的对象设置为returnVal对象。 for(int i=0;i
(&(objectCategory=user)(|(CN=)(sAMAccountName=))
无效,因为它不知道要与之进行比较的
CN
属性和
sAMAccountName
属性

(&(objectCategory=user)(|(CN=something)(sAMAccountName=someName))有效。
用对您有意义的内容替换某物和someName。

(&(objectCategory=user)(|(CN=)(sAMAccountName=))
无效,因为它不知道要与之进行比较的
CN
属性和
sAMAccountName
属性


(&(objectCategory=user)(|(CN=something)(sAMAccountName=someName)))
有效。用对您有意义的内容替换某物和某物名称。

您是否已作为域用户进行身份验证?否身份验证已设置为Windows您是否已作为域用户进行身份验证?否身份验证已设置为windowsdirSearcher.Filter=string.Format(&(objectCategory=user)(|(CN={0})(sAMAccountName={0})))“,用户名);它已经设置好了!我应该在这里共享我的ldap代码吗?@Pradit您最好打印出替换到字符串中的内容。我认为您可能使用了一些受限字符。您需要转义这些受限字符。请将筛选器字符串发送到调试控制台。它正在抱怨筛选器字符串。设置时一定有问题filter stringdirSearcher.filter=string.Format((&(objectCategory=user)(|(CN={0})(sAMAccountName={0}))),用户名);它已经设置好了!我应该在这里共享我的ldap代码吗?@Pradit您最好打印出替换到字符串中的内容。我认为您可能使用了一些受限字符。您需要转义这些受限字符。请将筛选器字符串发送到调试控制台。它正在抱怨筛选器字符串。设置时一定有问题过滤串