/// <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; }
/// <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))); }
public static void SetCurrentUser(this HttpSessionStateBase session, AdminUserInfo user) { session["CurrentUser_{50E9BEBB-3352-4259-9487-4B96F9D3E549}"] = user; }