コード例 #1
0
 public override bool ValidateUser(string username, string password)
 {
     if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
         return false;
         var user = UserManager.AuthenticateUser(username, password);
         //Store in cache
         var cacheKey = string.Format("UserData_{0}", username);
         var membershipUser = new AdminMembershipUser(user);
         HttpRuntime.Cache.Insert(cacheKey, membershipUser, null,
             DateTime.Now.AddMinutes(_cacheTimeoutInMinutes), Cache.NoSlidingExpiration);
         var roleCacheKey = string.Format("UserRoles_{0}", username);
         var userRoles = new string[] { null != user ? user.RoleName : string.Empty };
         //Store in cache
         HttpRuntime.Cache.Insert(roleCacheKey, userRoles, null,
             DateTime.Now.AddMinutes(_cacheTimeoutInMinutes), Cache.NoSlidingExpiration);
         return user != null;
 }
コード例 #2
0
        public override MembershipUser GetUser(string username, bool userIsOnline)
        {
            var cacheKey = string.Format("UserData_{0}", username);
            if (HttpRuntime.Cache[cacheKey] != null)
                return (AdminMembershipUser)HttpRuntime.Cache[cacheKey];
            var UserManager = new UserService();
            var user = UserManager.GetUser(username);
            if (user == null)
            {
                return null;
            }
            var membershipUser = new AdminMembershipUser(user);

            //Store in cache
            HttpRuntime.Cache.Insert(cacheKey, membershipUser, null, DateTime.Now.AddMinutes(_cacheTimeoutInMinutes), Cache.NoSlidingExpiration);

            return membershipUser;
        }