我想每天缓存两次active directory数据,即电子邮件、名字和姓氏。这应该在幕后发生,可能是在global.aspx application.start()中。现在,当And我想要获取1700个用户(我的应用程序允许浏览用户的功能)时,我会从缓存数据中获取。我的代码在Asp.net C#中。
有人能告诉我怎么做吗?
发布于 2011-07-06 21:16:44
我的代码在第一次被访问时运行(您可以通过在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; }
}https://stackoverflow.com/questions/6586012
复制相似问题