tags:

views:

25

answers:

2

Hi,

I have created an ASP.NET MVC application and created different kind of roles for my users. I have then created different kinds of AuthorizeAttributes for allowing/disallowing access to different Actions in my controls.

However I have got a lot of links that points to different of theese actions that are restricted for different roles. Can you somehow fix so that theese links get disabled automatically? I could of course add a lot of UserIsInRole(....)-stuff in my code but I really would prefer not to if there is a better way.

Du you have any suggestions?

+1  A: 

Are they in a list or menu? Is this something your controller could pass to your View? you could pass out a list of all allowed (or forbidden, whichever is more appropriate) and check that before you display a link.

if (allowedLink.Contans(myLink)
// show enabled link
else
//show disabled

The other good way would be to override the HtmlHelper for ActionLinks and make it do the check for permissions for you. Then if they do not have permissions, your html helper would display it disabled.

For examples, see this link http://www.asp.net/learn/mvc/tutorial-09-cs.aspx

Russell Steen
Oh, the second tip you gave me sounds like the way to go for me. Can you give me some code hints?
Freddy
Added a link to a good tutorial on the topic.
Russell Steen
A: 
Loadmaster
He's not asking how to disable, he's asking how to disable based on user permissions in a non-hacked-up fashion
Russell Steen
In that case, I'd add an attribute to each link, something like `canDo="xxx"`, which specifies the capability required for that link to work, then use Javascript to enable/disable the links dynamically, based on what capabilities the user actually has.
Loadmaster