"ThatsIT.net.au" <me@work> wrote in
news:98DCE730-D482-4752-9C99-:
> I have an application where different types of users login. depending
> what role they are in they are assigned a diffrent user object, admin
> dataEntry and so on.
>
> I can do this using some if statments and then makiung a instance of
> the corect object. the propble with this is that i have to do this on
> every page. what i would like to do is load the same commonUserObject
> for each user, and in the class then assign the right object as a
> child object. i could then access the object like this
>
>
> dim oUser as commonUserObject = new commonUserObject
> oUser.childObject.someMethod
>
> This will do, but i was wondering if there was a more elegent way of
> doing this, can i some how make the commonUserObject morph into the
> right object.
Set up an object with the common fields. You can load this into session
if you want to avoid going to the database all the time. For the more
specific objects, have them adorn the main user object. If you want, you
can lazy load the other object. This is where you are aiming for,
essentially.
Another method of doing this is to "subclass" the user object into more
specific objects with additional features. On pages you only need the
common bits, simply use it as a user object. On more specific pages,
GetType() and then cast as the other type of object and use the extra
bits.
If you are talking configuration bits (an employee has an SSN, but other
users do not), you can use the built in Profile bits and simply not
assign the extra items for other users. This is very flexible, but note
that the out of the box profile is a bit problematic if you get too
creative (and cleaning up a fubar is a pain). I use custom profile
providers for this reason.
Peace and Grace,
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
Twitter: @gbworld
Blog:
http://gregorybeamer.spaces.live.com
*******************************************
| Think outside the box! |
*******************************************