/// <summary>
 /// Default ctor
 /// </summary>
 /// <param name="identity"></param>
 /// <param name="user"></param>
 /// <param name="roles"></param>
 public AdminUserPrincipal(IIdentity identity, AdminUserInfo user, string[] roles = null)
     : base(identity, roles == null ? new string[] { } : roles)
 {
     this.User = user;
 }
예제 #2
0
        /// <summary>
        /// Set auth data based on user data
        /// </summary>
        /// <param name="user"></param>
        protected virtual void SetAuthData(AdminUserInfo user)
        {
            var roles = user.Roles.HasValue ? user.Roles.Value.GetRoleNames() : new string[] { };

            IPrincipal principal = new AdminUserPrincipal(new GenericIdentity(user.ID.ToString()), user, roles);

            this.HttpContext.User = principal;
            System.Threading.Thread.CurrentPrincipal = principal;

            //in the configuration file slidingExpiration is set as TRUE and timeout is set as sessions timeout => auth ticket is valid only for session period
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.ID.ToString(),
                DateTime.Now, DateTime.Now.AddMinutes(FormsAuthentication.Timeout.TotalMinutes), false, System.Web.Helpers.Json.Encode(user));

            this.HttpContext.Response.Cookies.Set(new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket)));
        }
예제 #3
0
 public static void SetCurrentUser(this HttpSessionStateBase session, AdminUserInfo user)
 {
     session["CurrentUser_{50E9BEBB-3352-4259-9487-4B96F9D3E549}"] = user;
 }