Jay*_*Jay 1 asp.net active-directory asp.net-3.5
与旧的和新的(呃).我搁置了一个旧的vb.net asp.net 2.0"asmx"服务,支持一个闪亮的新c#.net asp.net 4.0 WCF服务.
我的旧服务使用带有anr =过滤器的System.DirectoryServices.DirectorySearcher,效果很好,并允许从单个输入字段搜索用户对象的Google样式.
我真的想利用3.5的System.DirectoryServices.AccountManagement,但只能找到微软的"按示例查询"的变体:
UserPrincipal u = new UserPrincipal(ctx);
u.GivenName = "Jim";
u.Surname = "Daly";
PrincipalSearcher ps = new PrincipalSearcher();
ps.QueryFilter = u;
PrincipalSearchResult<Principal> results = ps.FindAll();
Run Code Online (Sandbox Code Playgroud)
我的问题是,我是否需要清除我的DirectorySearcher代码以进行类型搜索,或者我在AccountManagement命名空间中缺少一些明显的模糊搜索功能?
非常感谢.
J.
您可以编写自己的UserPrincipal实现来公开自定义属性:
[DirectoryObjectClass("user")]
[DirectoryRdnPrefix("CN")]
public class CustomUserPrincipal : UserPrincipal
{
public CustomUserPrincipal ( PrincipalContext context ) : base ( context )
{
}
[DirectoryProperty("anr")]
public string Anr
{
get { return (string)ExtensionGet ( "anr" )[0]; }
set { ExtensionSet ( "anr", value ); }
}
}
Run Code Online (Sandbox Code Playgroud)
用法
var u = new CustomUserPrincipal(ctx) { Anr = "*mr*" };
var ps = new PrincipalSearcher() { QueryFilter = u };
var results = ps.FindAll();
Run Code Online (Sandbox Code Playgroud)