AD DirSync需要旧的属性值以及新值

时间:2017-10-25 16:44:43

标签: c# ldap adlds

我一直在搜索高低,我找不到如何在ADLDS中获取已更改属性的旧值的示例。我创建了一个Web服务,使用Change Notifications监视更改,并且工作正常。我能够获得添加,更改和删除。但是,现在我需要能够为更改提供旧的和新的属性值。我想我需要使用DirSync,因为它只会返回已更改的属性。但是,它似乎只给了我新的价值。反正有没有返回旧的属性值是什么?如果这有帮助,这里是我正在使用的DirSync代码:

        BinaryFormatter bFormat = new BinaryFormatter();
        byte[] cookie = null;
        string strFileName = "cookie.bin";
        if (File.Exists(strFileName))
        {
            using (FileStream fsStream = new FileStream(strFileName, FileMode.OpenOrCreate))
            {
                cookie = (byte[])bFormat.Deserialize(fsStream);
            }
        }

        string str_dcName = "xx.x.xx.xx:5000";

        LdapConnection connection = new LdapConnection(str_dcName);

        connection.SessionOptions.ProtocolVersion = 3;
        connection.Credential = new System.Net.NetworkCredential("CN=administrator,ou=blah,dc=blahblah", "password");
        connection.AuthType = AuthType.Basic;
        connection.Bind();

        string[] attribs = new string[4];
        attribs[0] = "sn";
        attribs[1] = "isDeleted";
        attribs[2] = "displayname";

        SearchRequest request = new SearchRequest("OU=blah,DC=blahblah", "(|(objectClass=*)(isDeleted=TRUE))", SearchScope.Subtree, attribs);

        DirSyncRequestControl dirSyncRC = new DirSyncRequestControl(cookie, DirectorySynchronizationOptions.IncrementalValues, Int32.MaxValue);
        request.Controls.Add(dirSyncRC);

        bool bMoreData = true;
        SearchResponse searchResponse = (SearchResponse)connection.SendRequest(request);

        while (bMoreData) //Initial Search handler - since we're unable to combine with paged search
        {
            foreach (SearchResultEntry entry in searchResponse.Entries)
            {
                System.Collections.IDictionaryEnumerator attribEnum = entry.Attributes.GetEnumerator();
                while (attribEnum.MoveNext())//Iterate through the result attributes
                {
                    //Attributes have one or more values so we iterate through all the values 
                    //for each attribute
                    DirectoryAttribute subAttrib = (DirectoryAttribute)attribEnum.Value;
                    for (int ic = 0; ic < subAttrib.Count; ic++)
                    {
                        //Attribute Name below
                        Console.WriteLine(attribEnum.Key.ToString());
                        //Attribute Sub Value below
                        Console.WriteLine(subAttrib[ic].ToString());
                    }
                }
            }

            //Get the cookie from the response to use it in next searches

            foreach (DirectoryControl control in searchResponse.Controls)
            {
                if (control is DirSyncResponseControl)
                {
                    DirSyncResponseControl dsrc = control as DirSyncResponseControl;
                    cookie = dsrc.Cookie;
                    bMoreData = dsrc.MoreData;
                    break;
                }
            }
            dirSyncRC.Cookie = cookie;
            searchResponse = (SearchResponse)connection.SendRequest(request);
        }

        //Serialize the cookie into a file to use in next searches
        using (FileStream fsStream = new FileStream(strFileName, FileMode.Create))
        {
            //Serialize the data to the steam. To get the data for 
            //the cookie, call the GetDirectorySynchronizationCookie method.
            bFormat.Serialize(fsStream, cookie);
        }

        Console.WriteLine("Finished search...");
        Console.ReadKey();

感谢您的帮助!!

戴夫

0 个答案:

没有答案