K
K
kid-programmer2014-01-24 16:23:48
ASP.NET
kid-programmer, 2014-01-24 16:23:48

ASP MVC 5. How to switch roles for a user depending on which group he selects?

I use ASP MVC 5, the task is to switch the roles of the user depending on which group he selects. For example, there is group A and group B, each group has its own news, comments on the news, etc. For example, in group A, the user has rights to edit the news, and in group B, no, the user can freely switch between groups. Depending on which one he chooses, his roles change. Please tell me in which direction to dig, how to do it? Create a table where there will be a store of information about the roles of the user and group id-user_id-group_id-id_role and then, when selecting a group, delete-insert the necessary roles in the standard OWIN Forms authentication table.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kokcuk, 2014-01-25
@Kokcuk

I don’t pretend to be the ultimate truth, but I recently solved this problem like this:
In the database I started entities
1) page {controller, action},
2) userrole {pages}
3) user {userroles}
We create a page or automatically based on controllers this list we build, and not store in the database, create a role, assign the roles of the page and, accordingly, give the user different roles.
Next, we make our own attribute and inherit from AuthorizeAttribute, override AuthorizeCore, inside we get the name of the requested controller and method through httpContext.Request.RequestContext.RouteData , httpContext.User.Identity.Name we get the name of the user, well, then it’s a matter of technology, we get his roles, pages and see if it's allowed or not.
attribute can be written both above methods and above the entire controller.

A
aen, 2014-01-24
@aen

A user role is a user attribute, so it must be in a table with other user data.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question