I am trying to create a custom check, where I check if the role contains a user role. And I have problems with a string array, what is the best way to check if it contains a specific value?
public string[] AuthRoles { get; set; } public override void OnActionExecuting(ActionExecutingContext filterContext) { if (AuthRoles.Length > 0) { if (!filterContext.HttpContext.User.Identity.IsAuthenticated) { RedirectToRoute(filterContext, new { controller = "AdminLogin", action = "AdminLogin" }); } else { bool isAuthorized = filterContext.HttpContext.User.IsInRole(this.AuthRoles.??); if (!isAuthorized) throw new UnauthorizedAccessException("You are not authorized to view this page"); } } else { throw new InvalidOperationException("No Role Specified"); }
How do I change the check for User.IsInRole so that it processes the array?
source share