DefconDotNet

Untitled

Mar 12th, 2012
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System.Web.Mvc;
  2. using Freelancers.Infrastructure;
  3. using Freelancers.Infrastructure.Helpers;
  4. using Freelancers.Model;
  5. using System.Web;
  6. using Freelancers.Services;
  7.  
  8. namespace Freelancers.UI.Helpers
  9. {
  10.     public static class SessionHelper
  11.     {
  12.  
  13.         public static User Authenticated
  14.         {
  15.  
  16.             get
  17.             {
  18.                 var httpContext = HttpContextFactory.Current;
  19.                 Ensure.NotNull(httpContext, "httpContext");
  20.  
  21.                 if (httpContext != null && httpContext.Session != null)
  22.                 {
  23.  
  24.                     var currentUser = (User)httpContext.Session["AuthenticatedUser"];
  25.                     if (currentUser == null && httpContext.User.Identity.IsAuthenticated)
  26.                     {
  27.                         var userService = DependencyResolver.Current.GetService(typeof(IUserService)) as IUserService;
  28.                         Ensure.NotNull(userService, "UserService");
  29.                         if (userService != null)
  30.                         {
  31.                             currentUser = userService.GetUser(httpContext.User.Identity.Name);
  32.                             Authenticated = currentUser;
  33.                         }
  34.                     }
  35.  
  36.                     return currentUser;
  37.  
  38.                 }
  39.  
  40.                 return null;
  41.             }
  42.  
  43.             set {
  44.                 if (HttpContextFactory.Current.Session != null)
  45.                     HttpContextFactory.Current.Session["AuthenticatedUser"] = value;
  46.             }
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment