c# – 如何查询Active Directory中包含已删除对象的更改?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c# – 如何查询Active Directory中包含已删除对象的更改?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2827字,纯文字阅读大概需要5分钟。
内容图文
![c# – 如何查询Active Directory中包含已删除对象的更改?](/upload/InfoBanner/zyjiaocheng/790/8e80bcc3e7004737915a0fb07c03799a.jpg)
我使用下面的代码来查询AD中用户/ OU的更改.但它不会检索任何已删除的对象,不知道如何在此包含已删除的对象?
static void Main(string[] args)
{
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 = "xxxxx";
System.DirectoryServices.DirectoryEntry rootDSE = new System.DirectoryServices.DirectoryEntry("LDAP://rootDSE");
System.Net.NetworkCredential cr = new System.Net.NetworkCredential(@"xxx", "xxx", "xxx");
LdapConnection connection = new LdapConnection(str_dcName);
connection.Credential = cr;
connection.Bind();
string[] attribs = new string[3];
attribs[0] = "name";
attribs[1] = "description";
attribs[2] = "objectGUID";
SearchRequest request = new SearchRequest("DC=xxx,DC=xxx,DC=com", "(objectClass=*)", 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();
}
解决方法:
解决方案需要在请求对象中添加isDeleted = TRUE
SearchRequest request = new SearchRequest("DC=xx,DC=xxx,DC=com",
"(|(objectClass=organizationalUnit)(isDeleted=TRUE)(objectCategory=Person))",
SearchScope.Subtree, attribs);
内容总结
以上是互联网集市为您收集整理的c# – 如何查询Active Directory中包含已删除对象的更改?全部内容,希望文章能够帮你解决c# – 如何查询Active Directory中包含已删除对象的更改?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。