views:

48

answers:

2

I have Membership, Profile and Role providers setup for my .NET MVC website. I would like to say: this Role has access to that Page.

How do I 'inject' this code to the RoleProvider? Or do I have to override it somehow? Any leads?

(Roles are stored in the default ASP.NET SqlRoleProvider, Pages are stored in a seperate SQL database).

+2  A: 

Why would you inject this into the role provider? Why not just decorate the ActionResult [Authorise(Roles="myrole")]?

I understand that your pages are in the database but the action result still needs to call the view right?

I guess you could write you're own custom attribute which can check and either grant access or deny it.

I don't think the role provider is the right place for determining whether a page can be displayed or not.

griegs
Lol, I also have a custom FilterAttribute which checks if a user is authorized to view a page. How do I administrate this all? is the question i guess. :)
Ropstah
By administrate do you mean how do you create roles and assign users to it? Little confused as to the meaning here sorry @ropstah
griegs
No I can create roles and assign users. I need to 'assign' pages to roles, in a manageable way..
Ropstah
Ah ok!!! I just use the .net configuration manager to manage my roles. Then I guess you'd need a table that has your roles/roleIds and accessible pages/pageId's as a lookup table. Definately a custom attribute
griegs
You'd obviously need a page that will allow you to assign pages to roles. maybe a grid type of approach. there are some great jquery grids out there for that. or even a folder structure allowing you to select a page and then assign roles to them.
griegs
+1  A: 

Take a look at using sitemaps under asp.net. It is VERY easy to manage and to extend.

I have even used them as the datasource for a menu system.

Once in your page, you can do something like:

User.IsInRole("RoleName")
Gabriel McAdams
Hmmz, i currently have a custom SiteMapProvider. Am I missing something...? :)
Ropstah
In your custom sitemapprovider code, override the IsAccessibleToUser method and use context.User.IsInRole(role) - Then in your sitemap, you can add the roles attribute (roles="SysAdmin,Contributor")
Gabriel McAdams