using Infrastructure.Cache; using System; using System.Web; namespace Infrastructure.Auth { /// /// 身份认证服务实现(缓存可分布式部署) /// public class FormsAuthenticationService : IAuthenticationService { ICache cacheService; CacheSession cacheSession; HttpContext httpContext = HttpContext.Current; //hpf 缓存相关 public FormsAuthenticationService() { cacheService = DIContainer.Resolve(); cacheSession = new CacheSession(httpContext, true); } /// /// 获取当前认证的用户 /// /// 当前用户未通过认证则返回null public dynamic GetAuthenticatedUser() { if (httpContext == null || !cacheSession.IsAuthenticated) { return null;//hpf未登录 } return cacheService.Get(cacheSession.SessionId); } public void SignIn(string loginName, dynamic userInfo, TimeSpan expiration) { var sessionId = cacheSession.SessionId; cacheService.Set(sessionId, userInfo, expiration); } public void SignOut() { if (!string.IsNullOrEmpty(CacheKey.UserID)) { cacheService.Remove(CacheKey.UserID); } } } }