This was in my ApplicationController application:
protected override void OnAuthorization(AuthorizationContext filterContext) { var attributes = filterContext.ActionDescriptor.GetCustomAttributes(typeof(AuthorizeAttribute), true); if (attributes.Length == 0) attributes = GetType().GetCustomAttributes(typeof(AuthorizeAttribute), true); if (attributes.Length == 0) return; foreach (AuthorizeAttribute item in attributes) { if (!Thread.CurrentPrincipal.IsInRole(item.Roles)) { filterContext.Result = new RedirectResult("/Errors/Unauthorized"); } } }
I will reward everyone who has the best solution.
source share