【问题标题】:Ambiguous Name Resolution (anr=*ma*) equivalent in .NET 3.5 DirectoryServices.AccountManagement.NET 3.5 DirectoryServices.AccountManagement 中的模糊名称解析 (anr=*ma*) 等效项
【发布时间】:2010-07-07 13:27:54
【问题描述】:

与旧的并入新的(er)。 我正在搁置旧的 vb.net asp.net 2.0 “asmx”服务,转而使用闪亮的新 c#.net asp.net 4.0 WCF 服务。

我的旧服务使用带有 anr= 过滤器的 System.DirectoryServices.DirectorySearcher 效果很好,并允许从 单个 输入字段中对用户对象进行 Google 样式搜索。

我真的很想利用 3.5 的 System.DirectoryServices.AccountManagement,但只能找到 Microsoft 的“示例查询”的变体:

UserPrincipal u = new UserPrincipal(ctx);
u.GivenName = "Jim";
u.Surname = "Daly";
PrincipalSearcher ps = new PrincipalSearcher();
ps.QueryFilter = u;
PrincipalSearchResult<Principal> results = ps.FindAll();

我的问题是,我是否必须清除我的 DirectorySearcher 代码才能进行 anr 类型搜索,还是我在 AccountManagement 命名空间中缺少一些明显的模棱两可的搜索功能?

非常感谢。

J.

【问题讨论】:

    标签: asp.net active-directory asp.net-3.5


    【解决方案1】:

    您也许可以编写自己的 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 ); }
        }
    }
    

    用法

    var u = new CustomUserPrincipal(ctx) { Anr = "*mr*" };
    var ps = new PrincipalSearcher() { QueryFilter = u };
    var results = ps.FindAll();
    

    【讨论】:

    • 感谢您的解决方案,它对我来说很好,除了一件事:当我使用 * 作为通配符时,我没有得到任何结果。事实证明,如果您搜索 anr 属性,则不需要通配符。尽管它工作得很好。 T
    • 文档声明您不需要星号来进行类似搜索。 social.technet.microsoft.com/wiki/contents/articles/…
    猜你喜欢
    • 2017-06-24
    • 1970-01-01
    • 1970-01-01
    • 2018-04-17
    • 2010-09-21
    • 2015-10-30
    • 2013-01-20
    • 2010-09-20
    相关资源
    最近更新 更多