This project is read-only.

How to use new ASP.NET Identity 2.0 Roles and Authorize Attribute?

Apr 23, 2014 at 7:20 PM
I am using the new ASP.NET Identity 2.0 system. I know I can check if a user is in a role like this:
bool isAdmin = UserManager.IsInRole(User.Identity.GetUserId(), 
   "Customer Account Admin");
I guess this code can be written to check before certain code is run but what about the [Authorize] attribute. I used to be able say
[Authorize(Role="Customer Account Admin")]
This doesn't work anymore because I am not using the old membership or Role Management anymore. How can I put the two together? Or how do I guard against certain parts of the application not being available to members of the right role?
Apr 24, 2014 at 8:17 PM
The Authorize attribute should work. Check the UserAdminController an RolesAdminController in the Microsoft.AspNet.Identity.Samples for the functionality
Apr 24, 2014 at 8:20 PM
Apr 25, 2014 at 6:42 PM
For web forms you should be using the <authorization> tag in the web.config
Apr 25, 2014 at 6:44 PM
Edited Apr 25, 2014 at 6:47 PM
I am trying but I can't make it work. Please see SO POST
Jan 15, 2015 at 4:55 AM
If you have record like <roleManager enabled="true"/> in Web.config
You need to remove it.