userlevels - howto

  • Thread starter Thread starter ohmmega
  • Start date Start date
O

ohmmega

hello,

i'm new to c# and wanted to know a simple way to hide forms-stuff
(like buttons) depending on a user level:

example:

user1 logs in -> userlevel admin -> everything is just fine and
visible
user2 logs in -> userlevel oh_no -> only the log off button is visible

it should be possible to change the userlevel during runtime... hm. i
could do it the oldschool-way with if-then-else mnemonics, but i don't
wanna.

i already read about attributes and reflection - would this be a good
track to follow? are there other (maybe wiser) ways?

thank's for helping
rené p.
 
Rene,

You could use attributes, but you need some sort of pattern. Basically,
this is what code access security does, as you specify a role that the
current user has to be in to access the method/property, etc, etc.

What you could do is create an attribute of your own, and specify what
roles should be able to access which parts of the user interface. Then, you
can cycle through all the controls when the form is popped up, checking the
role of the current user vs the attribute, and delete the control or set the
visibility to false.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

hello,

i'm new to c# and wanted to know a simple way to hide forms-stuff
(like buttons) depending on a user level:

example:

user1 logs in -> userlevel admin -> everything is just fine and
visible
user2 logs in -> userlevel oh_no -> only the log off button is visible

it should be possible to change the userlevel during runtime... hm. i
could do it the oldschool-way with if-then-else mnemonics, but i don't
wanna.

i already read about attributes and reflection - would this be a good
track to follow? are there other (maybe wiser) ways?

thank's for helping
rené p.
 
Nicholas Paldino said:
Rene,

You could use attributes, but you need some sort of pattern.
Basically, this is what code access security does, as you specify a role
that the current user has to be in to access the method/property, etc,
etc.

What you could do is create an attribute of your own, and specify what
roles should be able to access which parts of the user interface. Then,
you can cycle through all the controls when the form is popped up,
checking the role of the current user vs the attribute, and delete the
control or set the visibility to false.

And I'd highly recommend accessing the attributes only once, and creating a
collection of the controls for each user level, and using that collection
each time the user changes. Reflection is slow.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

hello,

i'm new to c# and wanted to know a simple way to hide forms-stuff
(like buttons) depending on a user level:

example:

user1 logs in -> userlevel admin -> everything is just fine and
visible
user2 logs in -> userlevel oh_no -> only the log off button is visible

it should be possible to change the userlevel during runtime... hm. i
could do it the oldschool-way with if-then-else mnemonics, but i don't
wanna.

i already read about attributes and reflection - would this be a good
track to follow? are there other (maybe wiser) ways?

thank's for helping
rené p.
 
Back
Top