asp.net mvc decorate [Authorize()] with multiple enums

Here is a simple and elegant solution which allows you to simply use the following syntax: [AuthorizeRoles(MyEnum.Admin, MyEnum.Moderator)] When creating your own attribute, use the params keyword in your constructor: public class AuthorizeRoles : AuthorizeAttribute { public AuthorizeRoles(params MyEnum[] roles) { … } protected override bool AuthorizeCore(HttpContextBase httpContext) { … } } This will allow … Read more

How do I serve up an Unauthorized page when a user is not in the Authorized Roles?

Add something like this to your web.config: <customErrors mode=”On” defaultRedirect=”~/Login”> <error statusCode=”401″ redirect=”~/Unauthorized” /> <error statusCode=”404″ redirect=”~/PageNotFound” /> </customErrors> You should obviously create the /PageNotFound and /Unauthorized routes, actions and views. EDIT: I’m sorry, I apparently didn’t understand the problem thoroughly. The problem is that when the AuthorizeAttribute filter is executed, it decides that the … Read more

Angular2 routing canActivate and AuthGuard (JWT) with user role parameter

You can set the data parameter of the route with the role like this const appRoutes: Routes = [ { path: ‘account/super-secure’, component: SuperSecureComponent, canActivate: [RoleGuard], data: { roles: [‘super-admin’, ‘admin’] } }]; and then have this in canActivate of RoleGuard: canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { let roles = route.data[“roles”] as Array<string>; return (roles … Read more

Best Role-Based Access Control (RBAC) database model [closed]

To my rather basic knowledge in that area, the basic actors of an RBAC are: Resources. Permissions. Users. Roles (i.e. Groups). Resources <- require -> (one or many) Permissions. Roles <- are collections of -> (one or many) Permissions. Users <- can have -> (one or many) Roles. The tables for such a model would … Read more

Role based authentication in the new MVC 4 Internet template using simplemembership

Found an answer here by Mehdi Golchin which seems to take care of: [Authorize(Roles=”admin,editor,publisher”)] If I also add this to the home controller: [InitializeSimpleMembership] Because this attribute is on the Accounts controller, SimpleMembership database gets initialize only after the first use of the accounts controller like login/register. Even when the current user gets logged in … Read more