Search code examples
c#.netasp.net-mvc-5claims-based-identityasp.net-roles

MVC 5 - Roles - AuthorizeAttribute outdated


In my previous post i asked how to check/add user roles, but now i face another problem. Since microsoft moved to the new Identity 2.0, AuthorizeAttribute doesn't work anymore.

Is there any substitute filter for the Authorize?

EDIT:

I've made some tests and [Authorize(Users = "SOME_ID")] works, but not [Authorize(Roles = "Admin")].

And i verified if the user was really in that role (Admin)


Solution

  • Actually [Authorize(Roles = "ROLENAME")] working fine.

    Check your userRoles (or AspNetUserRoles) table for assigned roles for the id your have used that is SOME_ID according to your question. If not you have to correctly assign role "Admin" to the users when you create users.

    hope this helps.