Author: xmen | Posted on: 1/23/2010 8:29:53 AM | Views : 259

I have a big site that needs to call Membership.GetUser() plenty of times. So, what I thought is to push MembershipUser in Cache for 10 seconds and get it when need meanwhile. And I wrote code like this


public static MembershipUser GetCurrentUser() { System.Security.Principal.IIdentity identity = HttpContext.Current.User.Identity; if (identity.IsAuthenticated) { string key = "User_" + identity.Name; MembershipUser tuser; if (HttpRuntime.Cache[key] != null) tuser = (MembershipUser)HttpRuntime.Cache[key]; else { tuser = Membership.GetUser(identity.Name); if (tuser != null) { HttpRuntime.Cache.Add(key, tuser, null, DateTime.UtcNow.AddSeconds(10), ...

Go to the complete details ...