barnacle.m
barnacle.m

Reputation: 2200

Add User to ApplicationRole by RoleId

I noticed that when using the UserManager class, with the AddToRole method, you can only add users to roles by name, not by role ID. Is there a way to do this? The way my system is built, more than one role may have the same name. I'm looking for something like:

UserManager.AddToRole(user.UserId, role.RoleId);

where AddToRole has the arguments UserId and RoleId.

Upvotes: 2

Views: 513

Answers (1)

Jason Lesser
Jason Lesser

Reputation: 59

Your role names should be unique. If you have role names that are the same, how do you differentiate between them?

You could use linq and get the name from the your ID Roles.Where(r => r.Id == YourRoleId).First().Name ?

Upvotes: 1

Related Questions