public static UserProfileSessionData Get() { //From Session if (HttpContext.Current.Session[userProfile] != null) { return(HttpContext.Current.Session[userProfile] as UserProfileSessionData); } var userID = CookieStorage.Get(userCookieName); Guid id; //From Cookies if (string.IsNullOrEmpty(userID) == false && Guid.TryParse(userID, out id) == true) { UserRepository userRepository = new UserRepository(new plat2platContext()); var user = userRepository.GetUserByID(id); if (user != null) { UserProfileSessionData userProfile = new UserProfileSessionData(user); UserStorage.Set(userProfile); Log.Information("Get user from cookie"); return(userProfile); } } //From DB UserSessionRepository us = new UserSessionRepository(new plat2platContext()); UserSession userSession = us.GetUserSessionBySessionID(HttpContext.Current.Session.SessionID, DateTime.Now.AddDays(-5)); if (userSession != null) { Log.Information("Get user from DB"); return(UserStorage.Set(userSession.User)); } //if (HttpContext.Current.User.Identity != null // && string.IsNullOrEmpty(HttpContext.Current.User.Identity.Name) != null) //{ //} //if (FormsAuthentication.GetAuthCookie() //{ //} return(null); }