Active directory 缓存Active Directory数据

Active directory 缓存Active Directory数据,active-directory,Active Directory,我想缓存active directory数据,即电子邮件、名字和姓氏,每天两次。这应该在后台进行,可能在global.aspx application.start中。现在,当我想获取1700时,我的应用程序允许浏览用户的功能,我会从缓存的数据中获取。我的代码是Asp.NETC 有人能告诉我怎么做吗。我的代码在第一次被访问时运行。你可以在global.asax文件中放几行代码来启动这个应用程序。它将缓存的数据存储在ASP.Net缓存中12小时。12小时后,缓存将在下次访问数据时刷新 public

我想缓存active directory数据,即电子邮件、名字和姓氏,每天两次。这应该在后台进行,可能在global.aspx application.start中。现在,当我想获取1700时,我的应用程序允许浏览用户的功能,我会从缓存的数据中获取。我的代码是Asp.NETC


有人能告诉我怎么做吗。

我的代码在第一次被访问时运行。你可以在global.asax文件中放几行代码来启动这个应用程序。它将缓存的数据存储在ASP.Net缓存中12小时。12小时后,缓存将在下次访问数据时刷新

public class UserInfo
{
    public static List<UserInfo> UserInfoCache { 
        get{
            if(HttpContext.Current.Cache["CachedUserList"] == null) {
                PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

                PrincipalSearcher ps = new PrincipalSearcher(new UserPrincipal(ctx) { SamAccountName = "*" });

                var users = ps.FindAll();

                var result = from c in users
                             let u = (UserPrincipal)c
                             select new UserInfo() { Email = u.EmailAddress, FirstName = u.GivenName, LastName = u.Surname };

                HttpContext.Current.Cache.Insert("CachedUserList", result, null, DateTime.Now.AddHours(12), System.Web.Caching.Cache.NoSlidingExpiration);
            }

            return (List<UserInfo>)HttpContext.Current.Cache["CachedUserList"];
        }
    }

    public string Email { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

我这样做了,但是在缓存中。Insert向我显示错误:值不能为null。参数名称:value