Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Web.Mvc;
- using Freelancers.Infrastructure;
- using Freelancers.Infrastructure.Helpers;
- using Freelancers.Model;
- using System.Web;
- using Freelancers.Services;
- namespace Freelancers.UI.Helpers
- {
- public static class SessionHelper
- {
- public static User Authenticated
- {
- get
- {
- var httpContext = HttpContextFactory.Current;
- Ensure.NotNull(httpContext, "httpContext");
- if (httpContext != null && httpContext.Session != null)
- {
- var currentUser = (User)httpContext.Session["AuthenticatedUser"];
- if (currentUser == null && httpContext.User.Identity.IsAuthenticated)
- {
- var userService = DependencyResolver.Current.GetService(typeof(IUserService)) as IUserService;
- Ensure.NotNull(userService, "UserService");
- if (userService != null)
- {
- currentUser = userService.GetUser(httpContext.User.Identity.Name);
- Authenticated = currentUser;
- }
- }
- return currentUser;
- }
- return null;
- }
- set {
- if (HttpContextFactory.Current.Session != null)
- HttpContextFactory.Current.Session["AuthenticatedUser"] = value;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment