0

我有以下 Repository 方法来检索当前的 Active Directory 用户:-

public List<DomainContext> GetADUsers(string term=null)
{
    List<DomainContext> results = new List<DomainContext>();
    using (var context = new PrincipalContext(ContextType.Domain, "WIN-SPDEV"))
    using (var searcher = new PrincipalSearcher(new UserPrincipal(context)))
    {
        var searchResults = searcher.FindAll();



        foreach (Principal p in searchResults)
        {
           if (term == null || p.SamAccountName.ToString().ToUpper().StartsWith(term.ToUpper()))
           {
            DomainContext dc = new DomainContext();
            dc.DisplayName = p.DisplayName;
            dc.UserPrincipalName = p.UserPrincipalName;
            dc.Name = p.Name;
            dc.SamAccountName = p.SamAccountName ;
            dc.DistinguishedName =     p.DistinguishedName;

            results.Add(dc);

        }}
    }
    return results;
}

因此,作为 AD 用户,不会经常更改,因此我需要将此方法的结果缓存大约 2 小时。所以对这个方法的任何调用都不应该调用 Active Directory 吗?我实际上是在尝试实现与[OutputCache]Action 方法上定义的逻辑相同的逻辑。问候

4

1 回答 1

1

由于为您编写整个解决方案有点困难,我将指向Microsoft Patterns & Practices Caching Application Block

阅读文档,您需要的实现应该非常简单。

我希望它有帮助!

编辑:

我找到了更新的文档:http: //msdn.microsoft.com/en-us/library/ff953179%28v=pandp.50%29.aspx

于 2013-07-18T16:30:30.833 回答