[英]Mono & Active Directory: DirectoryServices.AccountManagement exception
[英]Searching Active Directory for a user with a certain property using DirectoryServices.AccountManagement
我是不熟悉Active Directory的System.DirectoryServices.AccountManagement
,建議我使用System.DirectoryServices.AccountManagement
命名空間,但我不知道如何在其中搜索具有某些縮寫的用戶。
有什么幫助嗎?
這是使用PrincipalSearcher
的完整示例,即使您願意,也可以使用您自己的屬性(代碼按原樣)。
/* Looking for users
*/
PrincipalContext domainContext = new PrincipalContext(ContextType.Domain, "WM2008R2ENT:389", "dc=dom,dc=fr", "jpb", "root.123");
/* Create a user principal to look for
*/
slxUser aSlxUser = new slxUser(domainContext);
aSlxUser.streetAddress = "The Adress"
/* FindAll
*/
PrincipalSearchResult<Principal> results = new PrincipalSearcher(aSlxUser).FindAll();
Console.WriteLine(results.Count());
使用slxUser的此定義:
[DirectoryObjectClass("user")]
[DirectoryRdnPrefix("CN")]
class slxUser : UserPrincipal
{
public slxUser(PrincipalContext context)
: base(context) { }
public slxUser(PrincipalContext context, string samAccountName, string password, bool enabled ) : base(context, samAccountName, password, enabled)
{
}
[DirectoryProperty("streetAddress")]
public string streetAddress
{
get
{
object[] result = this.ExtensionGet("streetAddress");
if (result != null)
{
return (string)result[0];
}
else
{
return null;
}
}
set { this.ExtensionSet("streetAddress", value); }
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.