Answer the question
In order to leave comments, you need to log in
How to specify a link depending on the role?
Hello!
Interested in the following question:
I have many roles. I want a certain controller to be launched based on the role.
I use the mvc template and there is already a built-in registration and classes for working with user data.
How to find out the user's role? What are the distribution options depending on the role? Perhaps there is another way to implement it.
Thanks in advance!
Answer the question
In order to leave comments, you need to log in
You can use the Authorize attribute - you can "hang" it either entirely on the controller or on the action method - read the literature on MVC.
The question is strange: write the IsUserInRole method or somehow implement it as it should (the MembershipAPI, for example, already has an implementation). In MVC, the User.Identity object is available at any time, from which you can pull out the Username property. By username, you can determine its role - I don’t see much of a problem. You can also write your own "wrapper" over the user object, "shove" roles into its properties or add a bunch of properties of the Is type, for example: IsAdmin, IsGuest, then access these properties - this is how your fantasy will work.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question