ladp3 获取属性_Ldap获取ad属性的方法.

博客给出了LADP3相关的代码实现,包含通过账户获取用户条目、设置属性和获取属性的方法。`GetUserEntryByAccount`方法用于根据账户查找用户条目,`SetProperty`方法可设置属性值,`GetProperty`方法能获取属性值。

---恢复内容开始---

public static DirectoryEntry GetUserEntryByAccount(DirectoryEntry entry, string account)

{

DirectorySearcher searcher = new DirectorySearcher(entry);

searcher.Filter = "(&(objectClass=user)(SAMAccountName=" + account + "))";

SearchResult result = searcher.FindOne();

entry.Close();

if (result != null)

{

return result.GetDirectoryEntry();

}

return null;

}

Set Property

public static void SetProperty(DirectoryEntry entry, string propertyName, string propertyValue)

{

if (entry.Properties.Contains(propertyName))

{

if (string.IsNullOrEmpty(propertyValue))

{

object o = entry.Properties[propertyName].Value;

entry.Properties[propertyName].Remove(o);

}

else

{

entry.Properties[propertyName][0] = propertyValue;

}

}

else

{

if (string.IsNullOrEmpty(propertyValue))

{

return;

}

entry.Properties[propertyName].Add(propertyValue);

}

}

Get Property

public static string GetProperty(DirectoryEntry entry, string propertyName)

{

if (entry.Properties.Contains(propertyName))

{

return entry.Properties[propertyName].Value.ToString();

}

else

{

return string.Empty;

}

}

---恢复内容结束---

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值