Guilherme Longo
Guilherme Longo

Reputation: 2308

Asp Net MVC Membership - Retrieving access rules for Roles. Is there how?

Is there a way to retrieve all access rules from a specific Role?

As roles are just flagged at the top of an action or on top of the whole class I can´t find a way to retrieve this information unless I read and parse the whole file and after that find a way to link this [authorization] tag to a group.

Thanks

Upvotes: 0

Views: 326

Answers (1)

Jan
Jan

Reputation: 16042

No there is no builtin way. Its even impossible, because you might check for Roles in your code (actions/views) as well.

And how should the list of access rules be returned?

For example, how should an algorithm return / name this access rule in a view:

@if(User.IsInRole("SomeRole") {
   <div>
       Show some html only visible for users in SomeRole
   </div>
}

You have to administer the list of your application defined access rules by yourself - i list will be very specific for your app.

Of cause, when you just use the Authorize attribute, you could generate a list of action methods accessible for a given role by reflecting over all controller classes.

Upvotes: 1

Related Questions