/// <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())
         {
             using (SiteDB db = new SiteDB())
             {
                 var user = UserRepository.GetUser(db, FormsAuthService.GetCurrentUserId());
                 if (user != null)
                 {
                     return user.Username;
                 }
                 else
                 {
                     return "";
                 }
             }
         }
         else
         {
             return "";
         }
     }
                ));
 }
 /// <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())
             {
                 using (SiteDB db = new SiteDB())
                 {
                     var user = UserRepository.GetUser(db, FormsAuthService.GetCurrentUserId());
                     if (user != null)
                     {
                         return user.Username;
                     }
                     else
                     {
                         return "";
                     }
                 }
             }
             else
             {
                 return "";
             }
         }
     );
 }
Example #3
0
        public HomeController(IFormsAuthenticationService FormsAuthService)
        {
            _db = new SiteDB();
            _log = new UserActivity(_db);

            this.FormsAuthService = FormsAuthService;

            //since CurrentUserId is used a lot save it in a variable right away for easier to read code.
            if (System.Web.HttpContext.Current.Request.IsAuthenticated)
            {
                CurrentUserId = FormsAuthService.GetCurrentUserId();
            }
        }