Esempio n. 1
0
        public static void SetCookieWithRoles(SystemRole role, string username, bool persist)
        {
            string roles = role.ToString();

            FormsAuthenticationConfiguration sect =
                ((AuthenticationSection)ConfigurationManager.GetSection("system.web/authentication")).Forms;
            FormsAuthenticationTicket authTicket = new
                                                   FormsAuthenticationTicket(1, username, DateTime.Now,
                                                                             persist ? DateTime.Now.AddYears(50) : DateTime.Now.AddMinutes(sect.Timeout.TotalMinutes),
                                                                             persist, roles);
            string     encryptedTicket = FormsAuthentication.Encrypt(authTicket);
            HttpCookie cook            = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

            cook.Expires = authTicket.Expiration;             //TODO: check
            HttpContext.Current.Response.Cookies.Set(cook);
        }
 public bool IsUserInSystemRole(string userId, SystemRole roleName)
 {
     return(IsUserInRole(userId, roleName.ToString()));
 }