public static void Configure(AuthorizationRuleManager manager) { manager.SetAuthorizationFailedUrl("~/AuthorizationFailed"); manager.RootDirectory .AddRule <UserRule>("?", CustomAuthorizationRuleAction.Deny) .AddCustomRule <AccessRuleAuthorizationRule>() .AddCustomRule <UserActivityAuthorizationRule>(); manager.Register("favicon.ico") .AddRule <UserRule>("?", CustomAuthorizationRuleAction.Allow) .AddRule <UserRule>("*", CustomAuthorizationRuleAction.Allow); manager.Register("Java") .AddRule <UserRule>("?", CustomAuthorizationRuleAction.Allow) .AddRule <UserRule>("*", CustomAuthorizationRuleAction.Allow); manager.Register("AuthorizationFailed") .AddRule <UserRule>("?", CustomAuthorizationRuleAction.Allow) .AddRule <UserRule>("*", CustomAuthorizationRuleAction.Allow); manager.Register("VtecTeamWebService") .AddRule <UserRule>("?", CustomAuthorizationRuleAction.Allow) .AddRule <UserRule>("*", CustomAuthorizationRuleAction.Allow); manager.Register("License") //.AddRule<RoleRule>(UserRole.AdminAreaAdmin.Code, CustomAuthorizationRuleAction.Allow) .AddRule <UserRule>("*", CustomAuthorizationRuleAction.Deny) .AddCustomRule <AccessRuleAuthorizationRule>() .AddCustomRule <UserActivityAuthorizationRule>(); }
private static void EnsureUniqueRule(AuthorizationRuleManager mgr, IAuthorizationRule rule) { IAuthorizationRule oldRule = null; if (rule.Element != null) oldRule = mgr.Rules.FirstOrDefault(c => c.Element != null && c.Element.Name == rule.Element.Name && c.Action == rule.Action); else oldRule = mgr.Rules.FirstOrDefault(c => c.Element == null && c.Action == rule.Action); if (oldRule != null) throw new ArgumentException("rule"); }
public static void ApplyPermissions(this MenuItemCollection source, IPrincipal user, AuthorizationRuleManager ruleManager) { foreach (MenuItem item in source) { if (item.HasChildren) { ApplyPermissions(item.Items, user, ruleManager); if (item.Items.All(x => x.Visible == false)) { item.Visible = false; } } if (String.IsNullOrEmpty(item.NavigateUrl) == false && ruleManager.IsUserAllowed(item.NavigateUrl, user) == false) { item.Visible = false; } } }