private IList<Role> getRoleListFromString(string strRoles) { IList<Role> roles = new List<Role>(); string[] arrRoles = strRoles.Split(','); foreach (string strRole in arrRoles) { Role role = new Role(); role.Name = strRole.Trim(); roles.Add(role); } return roles; }
/// <summary> /// Check whether user has this role or not. /// Note : If have '*' or '@' in your roles , it will be override all roles /// </summary> /// <param name="checkRole"></param> /// <returns></returns> public virtual bool IsInRole(Role checkRole) { // if checkRole = * so everyone can use if (checkRole.Name.Equals("*")) { return true; } // if checkRole = @ so just logged in user if (checkRole.Name.Equals("@")) { return !IsGuest; } if (checkRole.Name.Equals("%")) { return IsGuest; } IList innerRoles = Roles; // if does not has role then return false if(innerRoles == null) { return false; } foreach (Role role in innerRoles) { // if has role name so check if(role.Equals(checkRole)) { return true; } } return false; }