/// <summary> /// Return how we want to display the user's name in the UI. Currently set to Username, could be changed to First/Last, etc, /// </summary> /// <param name="FormsAuthService"></param> /// <returns></returns> public static string GetUserFriendlyName(IFormsAuthenticationService FormsAuthService) { return HttpContext.Current.Cache.GetOrStore<string>( GetUserSignInKey(FormsAuthService, UserFriendlyNameKey), () => { if (FormsAuthService.IsAuthenticated()) { var userRepository = new UserRepository(MvcApplication.SessionFactory.OpenSession()); var user = userRepository.GetUser(FormsAuthService.GetCurrentUserName()); if (user != null) { return user.Username; } else { return ""; } } else { return ""; } } ); }
/// <summary> /// Data is cached by User and their last login. So that the cache will reload when the user does a logout/login. /// </summary> /// <param name="FormsAuthService"></param> /// <param name="Prefix"></param> /// <returns></returns> public static string GetUserSignInKey(IFormsAuthenticationService FormsAuthService, string Prefix) { return (Prefix.AsNullIfWhiteSpace() ?? "") + FormsAuthService.GetCurrentUserName() + "-" + FormsAuthService.GetCurrentUserSignInTicks(); }
/// <summary> /// Data is cached by User and their last login. So that the cache will reload when the user does a logout/login. /// </summary> /// <param name="FormsAuthService"></param> /// <param name="Prefix"></param> /// <returns></returns> public static string GetUserSignInKey(IFormsAuthenticationService FormsAuthService, string Prefix) { return((Prefix.AsNullIfWhiteSpace() ?? "") + FormsAuthService.GetCurrentUserName() + "-" + FormsAuthService.GetCurrentUserSignInTicks()); }